Ordering datasets in a single plot

Hello,
Does anyone know how to change the order of datasets included in a single plot. I have plotted 4 variables and would like to rearrange their order. I can't find out how to do this. The default for plotting seems to be the order in which you updated the plot.
Thanks,

2 comentarios

Sean de Wolski
Sean de Wolski el 4 de Abr. de 2011
Can you show us a small example please? (input/operation/output)
Dave C
Dave C el 4 de Abr. de 2011
I didn't write any code to generate the graph.
plot(data1(:,1),data1(:,2))
plot(data2(:,1),data2(:,2))
plot(data3(:,1),data3(:,2))
plot(data4(:,1),data4(:,2))
Now, I want to show data1 1st, data4 2nd, data2 3rd, and finally data3 in 4th position. It is primarily to show the legend in ascending order.
Will I have to clear the plot and then change the order of the 4 plot commands?

Iniciar sesión para comentar.

Respuestas (3)

Sean de Wolski
Sean de Wolski el 4 de Abr. de 2011
figure; hold on
H(1) = plot(data1(:,1),data1(:,2),'r-')
H(2) = plot(data2(:,1),data2(:,2),'g*')
H(3) = plot(data3(:,1),data3(:,2),'bp')
H(4) = plot(data4(:,1),data4(:,2),'k:')
legend(H([3 2 1 4]),'3','2','1','4')
Paulo Silva
Paulo Silva el 4 de Abr. de 2011
d1=plot(data1(:,1),data1(:,2))
d2=plot(data2(:,1),data2(:,2))
d3=plot(data3(:,1),data3(:,2))
d4=plot(data4(:,1),data4(:,2))
legend([d1 d2 d3 d4],'one','two','three','four')
You can change the order by rearranging the values [d1 d2 d3 d4], for example [d4 d3 d2 d1]
legend([d4 d3 d2 d1],'four','three','two','one')
d4,d3,d2,d1 are handles for the plot objects.
Dave C
Dave C el 4 de Abr. de 2011

0 votos

Thanks,
I forgot about assigning handles to the plots.
Dave

Categorías

Etiquetas

Preguntada:

el 4 de Abr. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by