How to close mutiple uifigure using command

I run fig = uifigure many time in Matlab,so I genetared lots of uifigure ,I want to close all uifigure with one line of command.Do you know what command I should enter in Matlab.Thank you very much

 채택된 답변

Ameer Hamza
Ameer Hamza 2020년 10월 14일

10 개 추천

Run this
all_fig = findall(0, 'type', 'figure');
close(all_fig)

댓글 수: 6

bo peng
bo peng 2020년 10월 14일
thank you for your reply, your answer is correct,but I think Adam Danz's answer is I want.
Uzi Yona
Uzi Yona 2021년 10월 11일
Thanks a lot. This work very good.
bo peng
bo peng 2022년 4월 19일
your answer is so great !!!
Edward B
Edward B 2022년 9월 5일
That is the most concise and elegant two-liner since:
Take my wife.
Please.
Yang Liu
Yang Liu 2023년 11월 10일
Thank you, but don't take my wife. Your codes works for me, just a quick question:
What does the 0 represent? I try to figure out with help findall, and find nothing helpful...
Thanks, and take my wife now.
Voss
Voss 2024년 4월 4일
0 is the graphics root object, which is also returned by the groot function, so you could do findall(groot,_)

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Adam Danz
Adam Danz 2020년 10월 14일
편집: Adam Danz 2020년 10월 14일

4 개 추천

Just to add another approach,
Set HandleVisibility to on when you create the UIFigures. That way their handles will be visible to gcf() , close all, etc....
uifigure('HandleVisibility', 'on')

댓글 수: 5

bo peng
bo peng 2020년 10월 14일
your answer is so great
I2M
I2M 2021년 1월 4일
Yes very nice answer because when you move from guide to app it is not easy to uderstand that
Jan Kudlacek
Jan Kudlacek 2021년 12월 29일
편집: Jan Kudlacek 2021년 12월 29일
In Matlab 2019b HandleVisibility is 'off' and is read only. Is there any workaround?
Adam Danz
Adam Danz 2021년 12월 29일
@Jan Kudlacek, you can use Ameer Hamza's solution below.
Yang Liu
Yang Liu 2023년 11월 10일
I don't konw why but this doesn't work for me... weird...

댓글을 달려면 로그인하십시오.

Bjorn Gustavsson
Bjorn Gustavsson 2020년 10월 14일

0 개 추천

If you want to keep some figures you can close a subset of them if you keep the figure-handles in an array. If you modify your creation to something like this for all call to uifigure:
if ~exist('uifig')
uifig = uifigure;
else
uifig(end+1) = uifigure;
end
if ~exist('uifig')
uifig = uifigure;
else
uifig(end+1) = uifigure;
end
% ...etc
% then you can close some suitable set of them, or all of them
% closing all:
close([uifig]),clear uifig
% closing some:
close([uifig([1 3])]),uifig([1 3]) = [];
HTH

카테고리

도움말 센터File Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품

질문:

2020년 10월 14일

댓글:

2024년 4월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by