Assume that a script is running in Matlab. Is there any way to close all figures? (Closing each figure individually is tedious, and since the script is running I cannot add close all
to it.)
Asked
Active
Viewed 512 times
8

Franck Dernoncourt
- 77,520
- 72
- 342
- 501
-
@Daniel Thanks. I have upvoted each of them as they are interesting but Luis' solution closes editor files and yours close all figures every x seconds + requires editing the script. – Franck Dernoncourt Feb 16 '16 at 20:18
-
Not receiving any comment I assumed at least one of the answers is what you asked for. Maybe [this is more what you are asking for](http://stackoverflow.com/a/23712678/2732801)? I don't know a really good solution. – Daniel Feb 16 '16 at 20:22
-
@Daniel Thanks, the use case is as follows: sometimes, when Matlab is open, there are a lot of figure windows that got created over time. At some point, the user would like to close all figure windows (e.g. because the taskbar is too crowded, memory issue, etc.), without having to change any of the scripts that created the figure windows. The user still wants to be able to create new figure windows, so `-noFigureWindows` doesn't help for that case. It's indeed Matlab has no solution to achieve that yet. – Franck Dernoncourt Feb 16 '16 at 20:27
-
Not possible wile a script is running. The interpreter is single threaded. – Daniel Feb 16 '16 at 20:28
2 Answers
2
This works for me (tested in R2010b): in Matlab's command prompt, go to the menu bar, select Windows
, then Close All Documents
. This closes all figures, as well as editor files, while an m-file is running.

Luis Mendo
- 110,752
- 13
- 76
- 147
2
I recommend to run such scripts using a command line version of matlab, including the option -noFigureWindows
. If you want to run it in a full matlab UI (which is slower), use a timer object:
t = timer('TimerFcn',@(x,y)(close('all')), 'Period', 10.0);
start(t)
Don't forget to close and delete the timer after finishing your script.

Daniel
- 36,610
- 3
- 36
- 69