MATLAB Answers

How to close mutiple uifigure using command

49 views (last 30 days)
bo peng
bo peng on 14 Oct 2020
Commented: bo peng on 14 Oct 2020
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

  0 Comments

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 14 Oct 2020
Edited: Adam Danz on 14 Oct 2020
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')

More Answers (2)

Ameer Hamza
Ameer Hamza on 14 Oct 2020
Run this
all_fig = findall(0, 'type', 'figure');
close(all_fig)

  1 Comment

bo peng
bo peng on 14 Oct 2020
thank you for your reply, your answer is correct,but I think Adam Danz's answer is I want.

Sign in to comment.


Bjorn Gustavsson
Bjorn Gustavsson on 14 Oct 2020
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

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!