function rmfigures(varargin)
% function rmfigures(varargin)
% Purpose : Without input argument, it removes all user-generated figures.
% With 'all' as input argument, it removes figures and GUIs.
% Usage examples:
% >> rmfigures % remove only user figures
% >> rmfigures('all') % remove all figures and GUIs
%
oldStatus = get(0, 'showhiddenhandles');
if nargin == 0
set(0,'showhiddenhandles', 'off'); % make sure it is off
delete(findobj('Type', 'Figure'));
else
set(0, 'showhiddenhandles', 'On'); % Now, GUI handles can be seen
hf = findobj('Type', 'Figure');
delete(findobj('Type', 'Figure'));
end
set(0,'showhiddenhandles', oldStatus); % reset the status