Deleting plots within a GUI only if the plot exists?

1 回表示 (過去 30 日間)
Jeremy
Jeremy 2017 年 7 月 7 日
コメント済み: Adam 2017 年 7 月 7 日
How would I go about deleting specific plots within a GUI only if they exist? Thanks in advance. My code is below.
function deleting_plots(source,eventdata)
if exist('S.hDFplot1','plot')
delete (S.hDFplot1);
delete (S.hDFplot2);
end
  2 件のコメント
Jan
Jan 2017 年 7 月 7 日
From where is this function called? It looks like a callback. What is "S"? What is the contents of "S.hDFplot1"?
Adam
Adam 2017 年 7 月 7 日
If you have a finite number of plots that you are going to have at one time or another you can just declare a handle for each of them on your struct and initialise it to []
Then you don't need to care if it exists or not because calling delete on [] does not do any harm.
If you want to delete all plots then you could store all their handles in a single array of plot handles so you can delete them all in one go.

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

回答 (1 件)

Jan
Jan 2017 年 7 月 7 日
Perhaps S is your handles struct? Then:
function deleting_plots(source, eventdata)
S = guidata(source);
if ishghanlde(S.hDFplot1)
delete (S.hDFplot1);
delete (S.hDFplot2);
end
end
  2 件のコメント
Jeremy
Jeremy 2017 年 7 月 7 日
Thanks, but that doesn't seem to be working. I get the following two errors. I appreciate the help.
Not enough input arguments.
Error in DFtab/deleting_plots (line 113) S = guidata(source);
Adam
Adam 2017 年 7 月 7 日
You need to give more information. As much relevant information as possible. How the function is called or where it is linked up to as a callback is clearly fundamental information. How are we supposed to guess what S is? In your original code clearly S does not exist in the function workspace.

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

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by