Ordering datasets in a single plot
Show older comments
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 Comments
Sean de Wolski
on 4 Apr 2011
Can you show us a small example please? (input/operation/output)
Dave C
on 4 Apr 2011
Answers (3)
Sean de Wolski
on 4 Apr 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
on 4 Apr 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
on 4 Apr 2011
0 votes
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!