Question

I am trying to determine if there is a nice way, to close all figures in MATLAB, except for one(s) that I determine before hand, are not to be closed. Is there such a way to do this?

I am finding that I am wasting a lot of time chasing down specific stuff to close, every time my MATLAB script runs. Thank you.

Was it helpful?

Solution

You can try this

%figures to keep
figs2keep = [4, 7];

% Uncomment the following to 
% include ALL windows, including those with hidden handles (e.g. GUIs)
% all_figs = findall(0, 'type', 'figure');

all_figs = findobj(0, 'type', 'figure');
delete(setdiff(all_figs, figs2keep));

Here's the link to the source

OTHER TIPS

Probably the safest way is to assign handles to variables h1, h2, ... for each of your figures as you generate them and then use close(handle) to close the figures you don't want open.

close() also takes a vector/matrix of handles as an input, so you could always aggregate a vector of handles of figures to be closed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top