| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
| On this page… |
|---|
Creating New Files in the Editor Opening Existing Files in the Editor |
The MATLAB Editor provides a graphical user interface for basic text editing features for any file type, as well as for M-file debugging. The Editor is a single tool that you can use for editing, debugging, or both. There are various ways to start the Editor. The Editor automatically starts when you open a document or create a new one. Once started, you can customize the Editor to suit your needs.
This figure shows an example of the Editor outside of the desktop opened to an existing M-file, and calls out some of the tool's useful features.

You can create a new blank or prepopulated file in the Editor. A prepopulated file provides elements typically included in the file type you choose to open.
With the Editor as the current (active) window, you can:
Create an empty M-file (such as for a script) or a text file (such as for an XML or HTML file).
Choose File > New > Blank M-File or click the New M-File button
on the MATLAB desktop
toolbar.
Create an M-file prepopulated with basic M-file function elements.
Choose File > New > Function M-File.
Create a class definition M-file (classdef), prepopulated with basic M-file class structure elements.
Choose File > New > Class M-File.
In all cases, the Editor opens an untitled file in the MATLAB current folder.
Other tools also provide features for creating new M-files. For details, see:
You can do either of the following:
To create a blank unnamed file in the Editor, type edit in the Command Window.
To create a blank file named filename.ext in the Editor, type edit filename.ext. If filename.ext exists in the current folder or on the MATLAB search path, MATLAB opens the existing file. If filename.ext does not exist in the current folder or on the MATLAB search path, by default, a confirmation dialog box appears. It asks if you want to create the named file.
For more information about the confirmation dialog box, see Confirmation Dialogs Preferences.
To open an existing file in the Editor, click the Open file
button
on
the desktop or Editor toolbar, or select File > Open.
The Open dialog box appears, listing all M-files. You can see different files by changing the selection for Files of type in the dialog box. Type or select a file name, and click Open. If you access the Open dialog box from the desktop, the current folder files are shown, but if you access it from the Editor, the files in the folder for the current file are shown. For special considerations on the Macintosh platform, see Using File Browser GUIs on Macintosh Platforms to Navigate Within the MATLAB Root Folder.
The Editor opens, if it is not already open, with the file displayed. You can have multiple Editor files open at once, and the location of the files and the Editor are determined by document positioning guidelines. You can rearrange the documents to suit your needs. For details, see Opening and Arranging Desktop Documents.
To make a document in the Editor become the current document, click it, or select it from the Window menu or document bar.
If you open an M-file that contains M-file cells, yellow highlighting and gray horizontal lines might appear in the M-file, along with an information toolbar. Cell mode is used for publishing results and rapid code iteration. An M-file cell is denoted by a %% at the start of a line. MATLAB software interprets any M-file that contains %% at the start of a line as including cells and the Editor reflects the cell toolbar state and the cell display preferences, such as yellow highlighting of the current cell and gray lines between cells.
The first time you open an M-file that contains cells, an information
bar appears below the cell toolbar, providing links for details about
cell mode. To dismiss the information bar, click the close box on
the right side of the bar. The information bar does not appear again,
but you can get the same quick access to the information about M-file
cells from the Show Cell Mode information button
on the cell toolbar.
To hide the cell toolbar, right-click in the toolbar and select Cell Toolbar from the context menu. If you do not want cell mode enabled, select Cell > Disable Cell Mode. If cell mode is disabled when you quit a MATLAB session, it is disabled the next time you start a MATLAB session; the converse is true as well.
These are other ways to open files in the Editor:
Drag a file from another MATLAB desktop tool or a Microsoft tool into the Editor. For example, drag files from the Current Folder browser, or from Windows Explorer.
Open files from the Current Folder browser—see Opening and Running Files Using the Current Folder Browser.
Select a file to open from the most recently used files, which are listed at the bottom of the File menu in the Editor and all other desktop tools. You can change the number of files appearing on the list—select File > Preferences > Editor/Debugger and in the Most recently used file list, specify the Number of entries.
In the Editor or another desktop tool such as the Command Window, select a file name, right-click, and select Open Selection from the context menu to open that file. For details, see Opening a Selection in an M-File.
Set a preference that specifies that a MATLAB session, upon startup, is to automatically open the files that were open when the previous MATLAB session ended. Select File > Preferences > Editor/Debugger and in the Opening files in editor area, select the check box for On restart reopen files from previous MATLAB session.
Function Alternative for Opening an M-File. Use the edit or open function to open an existing file in the Editor. For example, type
edit collatz.m
to open the file collatz.m in the Editor, where collatz.m is on the search path or in the current folder. Use the relative or absolute path for the file you want to open if it is not on the search path or in the current folder.
You can arrange the size and location of M-files and other text documents you open in the Editor. Editor documents follow the same arrangement practices as other desktop documents. For details, see Opening and Arranging Desktop Documents.
You can edit any type of text file using the MATLAB Editor. For example, you can open and edit an HTML file. However, you can run or debug only M-files from the Editor.
When working with C/C++, Java, TLC, VHDL and Verilog programming languages, as well as XML or HTML, you can specify syntax highlighting and indenting preferences appropriate to those languages. Select File > Preferences > Editor/Debugger > Language. For details, click the Help button in the dialog box.
To close the Editor, click the Close box in the title bar of the Editor. This is different from the Close box in the menu bar of the Editor, which closes the current file when multiple files are open in a single window.

If multiple files are open, with each in a separate window, close each window separately. To close all files at once, select Close All Documents from the Window menu. Note that this will close other desktop documents as well, such as variables in the Variable Editor, and it will close the tools as well, that is, the Editor and Variable Editor, for example.
When you close the Editor and any of the open files have unsaved changes, you are prompted to save the files.
![]() | Ways to Edit, Evaluate, and Debug M-Files | Customizing the Editor by Setting Preferences | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |