フィルターのクリア

append legend in matlab 2015

12 ビュー (過去 30 日間)
N/A
N/A 2015 年 5 月 26 日
回答済み: Tyler Rhodes 2018 年 10 月 11 日
Hi,
In previous versions of Matlab, I could append a legend if I wanted or not, using the following code. This was very handy in case I didn't have all handles of plots at the beginning and just wanted to append the list of new plots. Any idea how to do this in Matlab 2015?
Many thanks M
[LEGH,OBJH,OUTH,OUTM] = legend; % reading handles
LEGH = legend([OUTH;hnew],OUTM{:},'newPlotName'); % append new plot
where 'hnew' is the handle of the new plot and ''newPlotName' its name.
  2 件のコメント
Alexander Mueller
Alexander Mueller 2015 年 5 月 26 日
Here's an example of how to update the legend to include newly added plots.
% plot 3 lines and add a legend
p=plot(magic(3));
l=legend(p,'plot1','plot2','plot3');
% add a fourth line, specifying the DisplayName
hold on
plot([5 5 5],':','DisplayName','plot4')
% turn legend off and back on.
legend('off');
legend('on');
N/A
N/A 2015 年 6 月 12 日
Hi Alexander, I just realized I have received your response, thanks.
I am missing a final point from your explanation above. What I am really interested in, is to remove (for example) the legend of the yellow line, while keeping the yellow line and all other legends... If you have any idea please let me know.
Thanks

サインインしてコメントする。

回答 (2 件)

JaeJun Lee
JaeJun Lee 2016 年 12 月 27 日
In my version(R2015b),
legend('on') did not work for me. It just created a legend named with 'on'. But 'show' just worked well.
legend('off')
legend('show')

Tyler Rhodes
Tyler Rhodes 2018 年 10 月 11 日
%first get the legend handles
old_legend=findobj(gcf, 'Type', 'Legend');
%then append the legend with new entry
legend([old_legend.String,'new_entry'])

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by