I recommend running such scripts using the command line version of matlab, including the -noFigureWindows option. If you want to run it in the full matlab user interface (which is slower), use a timer object:
t = timer('TimerFcn',@(x,y)(close('all')), 'Period', 10.0); start(t)
Remember to close and delete the timer after the script completes.
Daniel
source share