legend for hold function

7 ビュー (過去 30 日間)
Josefina Ottitsch
Josefina Ottitsch 2019 年 2 月 27 日
コメント済み: Josefina Ottitsch 2019 年 2 月 27 日
Hello,
I have a problem with a function I am using in a script.
in my script I am letting my program run through 1 file. The file consists of around 200 different but similar measurements, each measurement consists of around 500 x and y values.
in my script I tell my program to only plot lets say every 30th measurement. Therefore, my desired function plots around 200/30 = 6 graphs. I am using hold, so these 12 graphs are in one diagram.
My problem: I have difficulties setting up my legend.
currently the program looks like this:
for e=1:6
ee(e)=30*e
for i=1:length(ee)
legendstr{i}=num2str(ee(i));
legend('DisplayName','Measurement',legendstr)
hold all
end
end
while using this method, my legend only consists of the numbers 30 60 90 120 150 180 written downwards. But I cannot manage to write Measurement 30 Measurement 60 ... and so on
Does anyone know how to do this?
Thank you for the support!

採用された回答

Alex Mcaulley
Alex Mcaulley 2019 年 2 月 27 日
I think there is no 'DisplayName' property for a legend, it is aproperty of a chart, but you can do the same as you want just putting
for e=1:6
ee(e)=30*e
for i=1:length(ee)
legendstr{i}=['Measurement' num2str(ee(i))];
legend(legendstr)
hold all
end
end
Another option is setting in your plots the 'DisplayName' property. For example:
for e=1:6
ee(e)=30*e
plot(x,y,'DisplayName',['Measurement' num2str(ee(e))])
hold on
end
legend('show')
  1 件のコメント
Josefina Ottitsch
Josefina Ottitsch 2019 年 2 月 27 日
Thank you so much! I used the first answer and put a comma between measurement and num2str. It works now! Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by