| MATLAB® | ![]() |
| On this page… |
|---|
After making changes to a file, an asterisk (*) follows the file name in the title bar of the Editor. This indicates there are unsaved changes to the file.
To save the changes, use one of the Save commands in the File menu:
Save — Saves the file using its existing name.
If the file is newly created, the Save file
as dialog box opens, where you assign a name to the file
before saving it. Another way to save is by clicking the Save button
on the toolbar. If the file has not
been changed, Save appears dimmed, but
you can instead use Save As from the File menu to save to a different file name.
Save As — The Save file as dialog box opens, where you assign a name to the file and save it. By default, if you do not type an extension, MATLAB® software automatically assigns the .m extension to the file name. If you do not want an extension, type a . (period) after the file name.
Save All —
Saves all open files to their existing file names. For all newly created files,
the Save file as dialog box opens,
where you assign a name to each untitled file and save it. Another
way to save all open files is by clicking the Save All button
. This button is not on the toolbar
by default, however. For information on adding it, see Toolbars Preferences for the MATLAB® Desktop and Editor.
You cannot save an M-file while in debug mode. If you try to, MATLAB desktop displays a dialog box asking if you want to exit debug mode and then save the file. While debugging, you can execute sections of an M-file even though there are unsaved changes—see Running Sections in M-Files That Have Unsaved Changes.
The MathWorks™ recommends that you save M-files you create and M-files from The MathWorks that you edit to a directory that is not in the matlabroot/toolbox directory tree. If you keep your files in matlabroot/toolbox directories, they can be overwritten when you install a new version of MATLAB software.
Be aware that locations of files in the matlabroot/toolbox directory tree are loaded and cached in memory at the beginning of each MATLAB session to improve performance. Therefore, if you save files to matlabroot/toolbox directories using an external editor, or add or remove files from these directories using file system operations, run rehash toolbox before you use the files in the current session. If you make changes to existing files in matlabroot/toolbox directories using an external editor, run clear functionname before you use these files in the current session. For more information, see rehash or Toolbox Path Caching in the MATLAB® Program.
As you make changes to a file in the Editor, every 5 minutes the Editor automatically saves a copy of the file to a file of the same name but with an .asv extension. The autosave copy is useful if you have system problems and lose changes made to your file. In that event, you can open the autosave version, filename.asv, and then save it as filename.m to use the last good version of filename. For example, if you edit filename.m and do not save it for five minutes, MATLAB saves the file including the unsaved changes, to filename.asv.
Use autosave preferences to turn the autosave feature off or on, to specify the number of minutes between automatic saves, and to specify the file extension and location for autosave files. For details, select File > Preferences > Editor/Debugger > Autosave, and then click Help.
If the file you are editing is in a read-only directory and the autosave preference for location is the source file directory, an autosave copy of the file is not made.
Deleting Autosave Files. By default, autosave files are not automatically deleted when you delete the source file. To keep autosave to M-file relationships clear and current, it is a good practice when you rename or remove an M-file to delete or rename its corresponding autosave file.
There is a preference to Automatically delete autosave files. With this preference selected, when you close an M-file in the Editor, MATLAB automatically deletes the corresponding autosave file.
If you use a source control system for M-files, you can access it from within the Editor using File > Source Control. For more information, see Source Control Interface.
To print an entire M-file, select File > Print, or click the Print
button
on the toolbar. To print the current selection,
select File > Print
Selection. Complete the standard print
dialog box that appears.
Specify printing options for the Editor by selecting File > Page Setup. For example, you can specify printing with a header. For more information, see Printing and Page Setup Options for Desktop Tools.
To close the current M-file, select Close file name from the File menu, or click the Close box in the Editor menu bar. This is different from the Close box in the titlebar of the Editor, which closes all open files in that Editor window.

To close all files within the Editor, select Window > Close Editor Documents. This does not close any files undocked from the Editor. The Editor remains open with no files in it.
If each file is open in a separate window, close all the files at once using the Close All Documents item in the Window menu. Note that this also closes desktop documents of all types, including Variable Editor documents.
When you close a file that has unsaved changes, you are prompted to save the file. If you do not want to be prompted, hold Ctrl and click the Close box. The prompt will not appear and the document will close without saving any unsaved changes.
![]() | Keyboard Shortcuts in the Editor | Running M-Files in the Editor | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |