MATLAB: How to close all figures associated with the main Gui

closefigureguiguidehandleswindow

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

Best Answer

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.