How to close all figures associated with the main Gui?

14 ビュー (過去 30 日間)
hana
hana 2012 年 7 月 12 日
回答済み: H. Sh. G. 2021 年 10 月 21 日
I have a GUIDE gui. Let's say user didn't close the last session and is generating the gui again and there are some output figures associated with last session open still. How can I have the gui close all the extra figures without closing the main gui figure that has been just generated. I've tried to kill the individual figures with deleting their previous name, but no luck yet!! any help is appreciated
status = close(handles.hFig); % it is not recognizing handles.hFig
if status == 1
delete(handles.hFig);
else
end

採用された回答

Walter Roberson
Walter Roberson 2012 年 7 月 12 日
delete( setdiff( findall(0, 'type', 'figure'), The_Main_Figure_To_Keep ) );
That is, find all existing figures, exclude the one you want to keep from the list, and delete the rest.
  1 件のコメント
hana
hana 2012 年 7 月 12 日
編集済み: hana 2012 年 7 月 12 日
I came up with the following, but yours is more sophisticated. thanks
set(handles.figure_main,'HandleVisibility','off');
close all
set(handles.figure_main,'HandleVisibility','on');

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

その他の回答 (1 件)

H. Sh. G.
H. Sh. G. 2021 年 10 月 21 日
Hi,
I would simply use the following code:
function clf_all()
% Clear all figures
fh = get(0,'children');
nf = size(fh,1);
for i=1:nf
clf(get(fh(i),'Number'))
end

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by