Bypass a Line Plotted in the Legend

1 Ansicht (letzte 30 Tage)
Dima
Dima am 4 Feb. 2012
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

Antworten (2)

Bjorn Gustavsson
Bjorn Gustavsson am 4 Feb. 2012
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 Kommentare
Dima
Dima am 4 Feb. 2012
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 am 5 Feb. 2012
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

Melden Sie sich an, um zu kommentieren.


Walter Roberson
Walter Roberson am 5 Feb. 2012

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by