Holding legend with multiple plots
12 ビュー (過去 30 日間)
古いコメントを表示
I am using app designer and I have a plot that takes input from the interface then plots it. each time I am plotting, I'm holding the uiaxis on to keep previous plots. however I am not able to get the legend to update and maintain previous components. is it possible to do it?
2 件のコメント
回答 (2 件)
Suhas Maddi
2020 年 6 月 18 日
Hii,
I think You are trying to store the legend values for each iteration and add new values to that legend.
There are two ways to do so :
- Use a cell array of character vectors or string array or categorical array and append your new legend values to this cell array and plot the legend for every iteration.
- You can use legappend function as mentioned here: https://blogs.mathworks.com/pick/2014/07/25/append-entries-to-a-legend/
Hope this helps you.
2 件のコメント
Walter Roberson
2020 年 6 月 22 日
You would need to install legappend from https://www.mathworks.com/matlabcentral/fileexchange/47228-legappend or from the Add-On Explorer.
Suhas Maddi
2020 年 6 月 22 日
Hii ma sd,You can do something like this :
>>X=1:10;
>>Y=5:5:50;
>>Z=10:10:100;
>>labels={};
>>plot(X,Y);
>>labels{end+1}='label1';
>>legend(labels);
>>hold on
>>plot(X,Z);
>>labels{end+1}='label2';
>>legend(labels);
>>hold off
I am attaching the results too.
I hope this helps you.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!