legend for hold function

5 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Legend 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by