Skip to Main Content Skip to Search
Product Documentation

Create, Open, Save, and Close Files

Create New Files

With the Editor as the active window, you can:

Open Existing Files

To open an existing file or files in the Editor, choose the option that achieves your goals, as described in this table.

GoalStepsAdditional Information

Open with associated tool

Open a file using the appropriate MATLAB tool for the file type.

Select File > Open or click the Open file button on the toolbar.

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.

Select File > 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 subfunction 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 file

Reopen a recently used file.

At the bottom of the File menu, select a file.

To change the number of files on the list, select File > Preferences, and then 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.

Select File > Preferences > Editor/Debugger, and then select On restart reopen files from previous MATLAB session.

None.

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:

edit 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.

Save Files

After you modify a file, an asterisk (*) follows the file name in the title bar of the Editor. 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 OptionSteps

Save file to disk and keep file open in the Editor.

Select File > Save.

Rename file, save it to disk, and make it the active Editor document. Original file remains unchanged on disk.

  1. Select File > Save As.

  2. Specify a new name, type, or both for the file, and then click Save.

Save file to disk under new name. Original file remains open and unsaved.

  1. Select File > Save Backup.

    MATLAB opens the Select File for Backup dialog box.

  2. Specify a name and type for the backup file, and then click Save.

Save changes to all open files using current file names.

All files remain open.

  1. Select File > Save All.

    MATLAB opens the Select File for Save As dialog box for the first unnamed file.

  2. Specify a name and type for the unnamed file, and then click Save.

  3. Repeat step 2 until all unnamed files are saved.

Recommendations on Saving Files

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:

For more information, see rehash or Toolbox Path Caching in the MATLAB Program.

Autosaving Files

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 autosave version is useful if you have system problems and lose changes you 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.

Select File > Preferences > Autosave to select preferences to:

Close Files

To close the current file, click the Close button in the Editor menu bar. This is different from the Close button in the title bar of the Editor, which closes all open files in that Editor window.

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

To close all files within the Editor, select Window > Close Editor Documents. This menu option 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 Close All Documents in the Window menu. This 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 button. The prompt does not appear and the document closes without saving any unsaved changes.

Close the Editor

To close the Editor, click the Close button in the title bar of the Editor. This button is different from the Close button in the Editor menu bar. The latter Close button closes the active document when multiple documents are open in a single window.

Image of Editor title bar, menu bar, and toolbar. Use the Close button in the title bar to close the Editor. Use the Close button in the menu bar to close the active document.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

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