MATLAB: Closing all figures, but not GUI

close figures

How do I use "close command" to close all the other figures, but not the main GUI?
Actually here is a case in which a main GUI is opened and some other figures too. If I use "close all" it closes all figures including the GUI. Show me a way to close only the other figures.

Best Answer

I think you should be able to set handle visibility of your gui to 'off' then close all (which now won't see your figure) then turn it back on. You can do this:
set(handleToYourMainGUI, 'HandleVisibility', 'off');
close all;
set(handleToYourMainGUI, 'HandleVisibility', 'on');
Here's a fully tested demo, guaranteed to work:
% Open 8 figures.
figure(1);
% Create figure 2 and get it's handle.
% We're not interested in getting the handles of the other figures.
h2 = figure(2);
figure(3);
figure(4);
figure(5);
figure(6);
figure(7);
figure(8);
% Now close all except figure 2.
% First make figure 2 invisible.
set(h2, 'HandleVisibility', 'off');
% Close all visible figures. This won't include figure 2

uiwait(msgbox('Click OK to close all but figure 2'));
% Close all visible figures. This won't include figure 2
close all;
% Now make figure 2's handle visible again.
set(h2, 'HandleVisibility', 'on');