How to use legend command
3 views (last 30 days)
Show older comments
Sameer on 27 May 2014
Commented: Mahdi on 27 May 2014
I am having the data lets say for seven elements and I am ploting it using a loop in a single figure. But in these seven elements someof the elements contain nothing and then the plot for that is not plotted. Now how I can use the legend command only for the elements that are plotted?
Is the loop still telling the figure to plot even if there isn't any data recorded? You have a few ways around it:
The first one basically tells the legend to put an "empty" headline for the second item (if nothing was plotted)
legend('item1', '', 'item3')
You can also only tell MATLAB to plot only when there is data with
There are also other ways which you can tell the legend to ignore some entries. You can also enter the plot tools (in the top menu of figure) and do it without code.
Do you mean that you want the legend to be labelled differently based on the loop?
You can simply do something like this: (this is just an example)
% Do your plotting here
In this case, the legend would show Plot_1, Plot_2, Plot_3
More Answers (0)
Find more on Legend 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!