Saving, Printing, and Closing Files in the Editor

Saving Files

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:

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.

Recommendations on Saving Files

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.

Autosave

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.

Accessing Your Source Control System

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.

Printing M-Files

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.

Closing M-Files

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.

Image of Editor title bar, menu bar, and toolbar. Use the close box in the title bar to close the Editor. Use the close box in the menu bar to close the current document.

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.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS