Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

Starting, Creating Files, and Closing the Editor

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

Image of Editor outside of the desktop.

Creating New Files in the Editor

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:

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:

Function Alternative for Creating New Files

You can do either of the following:

For more information about the confirmation dialog box, see Confirmation Dialogs Preferences.

Opening Existing Files in the Editor

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.

M-File Cells

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.

Other Methods for Opening Files in the Editor

These are other ways to open files in the Editor:

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.

Arranging Editor Documents

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.

Creating and Editing Other Text File Types

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.

Closing the Editor

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.

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.

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.

  


Recommended Products

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