legend for hold function

7 visualizaciones (últimos 30 días)
Josefina Ottitsch
Josefina Ottitsch el 27 de Feb. de 2019
Comentada: Josefina Ottitsch el 27 de Feb. de 2019
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!

Respuesta aceptada

Alex Mcaulley
Alex Mcaulley el 27 de Feb. de 2019
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 comentario
Josefina Ottitsch
Josefina Ottitsch el 27 de Feb. de 2019
Thank you so much! I used the first answer and put a comma between measurement and num2str. It works now! Thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by