|On this page…|
To open an existing file or files in the Editor, choose the option that achieves your goals, as described in this table.
Open with associated tool
Open a file using the appropriate MATLAB® tool for the file type.
On the Editor (or Home) tab, in the File section, click
For example, this option opens a file with a .m extension in the Editor and loads a MAT-file into the Workspace browser.
Open as text file
Open a file in the Editor as a text file, even if the file type is associated with another application or tool.
On the Editor tab, in the File section, click Open , and select Open as Text.
This is useful, for example, if you have imported a tab-delimited data file (.dat) into the workspace and you find you want to add a data point. Open the file as text in the Editor, make your addition, and then save the file.
Open function from within file
Open a local function or function file from within a file in the Editor.
Position the cursor on the name within the open file, and then right-click and select Open file-name from the context menu.
You also can use this method to open a variable or Simulink® model.
For details, see Open a File or Variable from Within a File.
Reopen a recently used file.
At the bottom of the Open drop-down list, select a file under Recent Files.
To change the number of files on the list, click Preferences, and then select MATLAB and Editor/Debugger. Under Most recently used file list, change the value for Number of entries.
Reopen files at startup
At startup, automatically open the files that were open when the previous MATLAB session ended.
On the Home tab, in the Environment section, click Preferences and select MATLAB and Editor/Debugger. Then, select On restart reopen files from previous MATLAB session.
Open file displaying in another tool
Open a file name displaying in another MATLAB desktop tool or Microsoft® tool.
Drag the file from the other tool into the Editor.
For example, drag files from the Current Folder browser or from Windows® Explorer.
Open file using a function
|Use the edit or open function.|
For example, type the following to open collatz.m:
If collatz.m is not on the search path or in the current folder, use the relative or absolute path for the file.
For special considerations on the Macintosh platform, see Navigating Within the MATLAB Root Folder on Macintosh Platforms.
After you modify a file in the Editor, an asterisk (*) follows the file name. This asterisk indicates that there are unsaved changes to the file.
You can perform four different types of save operations, which have various effects, as described in this table.
Save file to disk and keep file open in the Editor.
On the Editor tab, in the File section, click .
Rename file, save it to disk, and make it the active Editor document. Original file remains unchanged on disk.
Save file to disk under new name. Original file remains open and unsaved.
Save changes to all open files using current file names.
All files remain open.
MathWorks® recommends that you save files you create and files from MathWorks that you edit to a folder that is not in the matlabroot/toolbox folder tree, where matlabroot is the folder returned when you type matlabroot in the Command Window. If you keep your files in matlabroot/toolbox folders, they can be overwritten when you install a new version of MATLAB software.
At the beginning of each MATLAB session, MATLAB loads and caches in memory the locations of files in the matlabroot/toolbox folder tree. Therefore, if you:
Save files to matlabroot/toolbox folders using an external editor, run rehash toolbox before you use the files in the current session.
Add or remove files from matlabroot/toolbox folders using file system operations, run rehash toolbox before you use the files in the current session.
Modify existing files in matlabroot/toolbox folders using an external editor, run clear function-name before you use these files in the current session.
When you modify a file in the Editor, the Editor saves a copy of the file using the same file name but with an .asv extension every 5 minutes. The backup version is useful if you have system problems and lose changes you made to your file. In that event, you can open the backup version, filename.asv, and then save it as filename.m to use the last good version of filename.
To select preferences, click Preferences, and then select MATLAB > Editor/Debugger > Backup Files on the Home tab, in the Environment section. You can then:
Turn the backup feature on or off.
Automatically delete backup files when you close the corresponding source file.
By default, MATLAB automatically deletes backup files when you close the Editor. It is best to keep backup-to-file relationships clear and current. Therefore, when you rename or remove a file, consider deleting or renaming the corresponding backup file.
Specify the number of minutes between backup saves.
Specify the file extension for backup files.
Specify a location for backup files
If you edit a file in a read-only folder and the back up Location preference is Source file directories, then the Editor does not create a backup copy of the file.