Development Environment |
Saving M-Files
After making changes to an M-file, you see an asterisk (*) next to the filename in the title bar of the Editor/Debugger. This indicates there are unsaved changes to the file.
To save the changes, use one of the Save commands in the File menu:
.m
extension because MATLAB automatically assigns the .m
extension to the filename. If you do not want an extension, type a .
(period) after the filename.
You cannot save a file while in debug mode. First, exit debug mode and then save the file.
Note
Save any M-files you create and any MathWorks-supplied M-files that you edit in 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. Also note 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. If you save files to $matlabroot/toolbox directories using an external editor or add or remove in 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 the files in the current session. For more information, see rehash or Toolbox Path Caching. |
As you make changes to a file in the Editor, every five minutes the Editor automatically saves a copy of the file to a file of the same name but with an .asv
extension. The autosaved copy is useful if you have system problems and lose changes made to your file. In that event, you can open the autosaved version, filename.asv
, and then save it as filename.m
to use the last good version of filename
.
Use Autosave Preferences for the Editor/Debugger 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 autosaved files.
Autosaved files are not automatically deleted when you delete the source file. So if, for example, you rename a file, delete the .asv
version of the original filename.
If the M-file you are editing is in a read-only directory, an autosave copy of the file is not made.
Running M-Files from the Editor/Debugger
You can run a script or a function that does not require an input argument directly from the Editor/Debugger. Click the run button on the toolbar, or select Run from the Debug menu.
If the file is not in a directory on the search path or in the current directory, a dialog box appears, presenting you with options that allow you to run the file. You can either change the current directory to the directory containing the file, or you can add the directory containing the file to the search path.
Note that if the file has unsaved changes, running it from the Editor/Debugger automatically saves the changes before running. In that event, the menu item is Save and Run.
See Running an M-File with Breakpoints for additional information about running M-files while debugging.
Incremental Search | Printing an M-File |