Bypass a Line Plotted in the Legend

1 次查看(过去 30 天)
Dima
Dima 2012-2-4
Hello!)
I wonder how do I bypass a line plot out of multiple plots when putting the legend on a chart.
Suppose I have 10 vectors plotted on a chart. If I wish to make the legend display the info for only the first 3 time series and only for the last one...how do I do that?
leg = legend('one','two','three','four','five','six','seven','eight','nine','ten','Location','SouthEast');
Thanks!
Dima

回答(2 个)

Bjorn Gustavsson
Bjorn Gustavsson 2012-2-4
If you call plot with an output argument:
ph = plot(randn(10));
You can select which lines to have in the legend:
legend(ph([1:3,end]),'1','2,'3','432')
HTH
  2 个评论
Dima
Dima 2012-2-4
YES)) but what if I have plotline for various functions put on one chart and I only want to have the legend for some of them?
Bjorn Gustavsson
Bjorn Gustavsson 2012-2-5
ph(1) = plot(x1,y1);
ph(2:3) = plot(x2,[y2;y3]);
...
ph(10) = plot(x12,y12);
legend as above.
Or you could store the plot-handles in cell arrays to store the plot handles.
legend([ph1{1}(2),ph{2}([4,3]),...],...)
HTH

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2012-2-5

类别

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