Ken & Mike on the MATLAB Desktop
July 16th, 2007
Closing Time at the Document Bar
When you are done working with a “document” (M-File in the Editor, variable in the Array Editor, docked Figure, etc.) MATLAB offers a plethora of ways to close it:
- You can select File->Close my document from the menu
- You can press Ctrl-W (while the document has focus)
- You can click the X to the upper right of the document
- You can click the X on the document bar button (tab) corresponding to the document
- You can even right click on the document bar button and select Close my document from the context menu.

What more could you want?
Well if the document you are closing is an M-File with unsaved changes; you probably want MATLAB to prompt you regarding the disposition of the changes. Indeed, MATLAB will do so in response to any of the above close gestures. If you happen to know that you want to discard your changes you can avoid the prompting dialog by holding down the Ctrl key while pressing either of the X’s. MATLAB will respond by closing the document and discarding any changes without prompting you. This Ctrl key trick extends to closing the Editor itself. If you hold down the Ctrl key and press the X on the Editor’s title bar, the Editor will close, discarding unsaved changes to all files.
Sometimes, instead of closing a particular document you might want to keep a particular document open and close all the others. As of R2006b, the document bar button context menu offers a “Close all except my document” item for just this eventuality. This can be handy but it can also be frustrating when you instead want to keep a few documents open rather than just one. Here’s this menu item offering to do almost, but not quite, what you want. The solution is to use the “Close…” item that also appears on the context menu as well as on the File menu. This item has been present since R2006b. Close… opens a dialog that lets you choose which files to close.

In order to use this dialog to close all but a few documents, click the “Select All” button, then within the list at the left individually deselect the documents you want to keep open. Click the “Close Selected” button and MATLAB will do your bidding.
Posted by Peter Muellers
Peter Muellers is a developer on the MATLAB desktop team. He works primarily on the desktop framework. Many of his better ideas occur while he is running, biking or sleeping.
8:51 am |
Posted in Desktop, Editor |
Permalink |
You can follow any responses to this entry through the RSS 2.0 feed.
You can skip to the end and leave a response. Pinging is currently not allowed.
Leave a Reply
|
I may be off topic, but would like to make a suggestion for keeping files in editor when closed inadvertently
How about having a confirmations dialog window when closing the editor (undocked).
I can’t remember hoe many times I have lost track of all files in the editor by clicking on close instead of minimize.
Would be nice to have this option in a future version
Thanks for pointing out this pitfall. We will consider doing something about it in a future release.
Documents, you don’t have to go home but you can’t stay here.
Had no idea about right clicking on the closing bar, or the close dialog box. Thanks!
And of course, props for the witty title.
Can you make a feature to open all subroutines? So if I open my file main.m I also get function1.m function2.m,script1.m if they are currently called by main.m (or by a subsidiary, so if main.m calls script1.m which calls function 4.m I want to view all 3 of them. )
Thanks.
Hi Margaret,
Thanks for the suggestion. We will consider something like this in the future.
-Christina