Sometimes I start a MATLAB script and realize too late that it is going to output way too many figures. Eventually I get an
Exception in thread \"AWT
I use the findobj function in my own function 'limfig', where imglimit sets the amount of figures you want to be allowed to open at one time.
function y=limfig
imglimit=15;
if length(findobj('type','figure'))
Save this short code as limfig.m and then in any other code use the line f=limfig instead of f=figure.