Overwrite data in figure but keep axis labels, title, and legend
32 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I would like to overwrite only the data presented in a figure while keeping the labels and legends the same. I do not want to waste space and time on re-labeling the figures. 'hold on' holds the plot but does not overwrite the existing data and only adds to it.
Thank you for your help.
0 件のコメント
採用された回答
Fangjun Jiang
2011 年 7 月 15 日
h=plot(rand(1,100));
title('random signal');
legend('blue signal');
set(h,'XData',1:10,'YData',1:10);
0 件のコメント
その他の回答 (2 件)
Jack LeBien
2016 年 8 月 6 日
Hi, you can use
hold on
cla
plot(newData)
cla (clear all) will remove the plotted data but not other formatting.
7 件のコメント
MechtEngineer
2014 年 4 月 8 日
編集済み: John Kelly
2022 年 10 月 31 日
I don't see how the previous answer keeps the axis labels, title and legend when plotting some new data on the same axis.
The code that worked for the author (and for me) was:
title('Some Title','HandleVisibility','off');
ylabel('Some ylabel','HandleVisibility','off');
xlabel('Some xlabel','HandleVisibility','off');
set(gca,'NextPlot','replacechildren') ;
Any subsequent plots on this axes keeps the existing axes properties (including title, axis labels and legend), while replacing child objects (e.g. data)
2 件のコメント
jinsong mao
2017 年 9 月 5 日
this method proves to be good, which can solve my problem, i want to keep the label in matlab gui while ploting in callback functions. thanks guys
参考
カテゴリ
Help Center および File Exchange で Title についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!