clear one plot in multiple (hold) figure

112 ビュー (過去 30 日間)
Ashton
Ashton 2011 年 2 月 16 日
コメント済み: Tomas 2022 年 11 月 18 日
I have a single figure/plot that contains multiple plots commands (not subplots - just multiple data sets). I need to be able to add the data to the current figure, see how it looks, and clear it if doesnt fit my visual criteria.
Any suggestions?
clf clears the entire figure. I just want to clear the last data set I added to the figure.

採用された回答

the cyclist
the cyclist 2011 年 2 月 16 日
figure
hold on
h1 = plot(1:10,'r');
h2 = plot(2:11,'g');
if <your condition doesn't hold>
set(h2,'Visible','off')
end
  3 件のコメント
Rik
Rik 2020 年 6 月 22 日
If you're using this code you aren't deleting the plot. You are just making the plot invisible. The solution is to set visible to 'on' again if you want to show the plot.
Tomas
Tomas 2022 年 11 月 18 日
Now if I were top do this inside a callback function i would do e.g.
h1 = plot(1:10,'r');
then how can I do the set(h2,'Visible','off') in a separate callback function?

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

その他の回答 (3 件)

Matt Tearle
Matt Tearle 2011 年 2 月 16 日
In addition to the cyclist's answer, you can also do
delete(h2)
to actually delete the line, rather than just hide it. Also, if you didn't store the handles on plotting ( h1 = plot(...) ) you can find them after the fact using findobj
h = findobj('type','line')
finds a vector of handles to all line objects. You could then delete(h(1))
  3 件のコメント
Wencai Lee
Wencai Lee 2011 年 4 月 6 日
Hi Jiro,
Do you know how to undo one step after using the delete(gco)?
Thanks!
Eric T
Eric T 2016 年 3 月 18 日
This seems a nice, principled answer. Don't like making them invisible because that takes up memory, def prefer to delete them!

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


Sai
Sai 2017 年 1 月 18 日
Go to 'View' and click on the 'Plot Browser' to enable it. There you can check/uncheck the plots in the figure

Ashton
Ashton 2011 年 2 月 16 日
Thanks guys!
  1 件のコメント
Matt Tearle
Matt Tearle 2011 年 2 月 16 日
You're welcome. And now the obligatory message: to help others who might have the same question, it would be great if you could vote for and/or accept answers that you think should be given prominence. Thanks. (I know there's only a couple of answers in this case, but it's good practice to let everyone know "answer X solved my problem")

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by