This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Check Syntax as You Type

Syntax Highlighting

To help you identify MATLAB® elements, some entries appear in different colors in the Command Window and the Editor. This is known as syntax highlighting. By default:

  • Keywords are blue.

  • Character vectors are purple.

  • Unterminated character vectors are maroon.

  • Comments are green.

% check to see if A is greater than B
if A > B
elseif A < B

Except for errors, output in the Command Window does not appear with syntax highlighting.

MATLAB software copies the selection to the Clipboard in RTF format, which many Microsoft® Windows® and Macintosh applications support. When you paste or drag a selection from the Editor to another application, such as Microsoft Word, the pasted text maintains the syntax highlighting colors and font characteristics from the Editor.

You can change syntax highlighting preferences. On the Home tab, in the Environment section, click Preferences. Select MATLAB > Editor/Debugger > Languages. Preference changes do not apply in live scripts.

Delimiter Matching

MATLAB indicates matched and mismatched delimiters, such as parentheses, brackets, and braces, to help you avoid syntax errors. MATLAB also indicates paired language keywords, such as for, if, while, else, and end statements.

By default, MATLAB indicates matched and mismatched delimiters and paired language keywords as follows:

  • Type a closing delimiter—MATLAB briefly highlights or underlines the corresponding opening delimiter.

  • Type more closing delimiters than opening delimiters—MATLAB puts a strikethrough or underline on the unmatched delimiter.

  • Use the arrow keys to move the cursor over one delimiter—MATLAB briefly underlines both delimiters in a pair. If no corresponding delimiter exists, MATLAB puts a strikethrough on the unmatched delimiter.

If a matching delimiter exists, but it is not visible on the screen, a pop-up window appears and shows the line containing the matching delimiter. Click in the pop-up window to go to that line.

The pop-up window for delimiter matching is not supported in live scripts.

You can change what the delimiter matching indicators are, and when or if they appear. On the Home tab, in the Environment section, click Preferences. Select MATLAB > Keyboard. Preference changes do not apply in live scripts.

Automatic Code Suggestions and Completions

When you write code, MATLAB automatically suggests and completes the names of functions, models, MATLAB objects, files, folders, variables, structures, graphics properties, parameters, and options. You can use automatic suggestions and completions to write commands faster and avoid typographical errors.

The Live Editor automatically displays possible matches as you type. To insert a match in your script, use the arrow keys to select the name you want, and then press the Tab key. Press the Esc key to clear the list of possible completions without selecting anything. To complete names in the Command Window or Editor, type the first few characters of the name you want to complete, and then press the Tab key. Use the arrow keys to select the name you want, and then press the Tab key again.

Automatic suggestions and completions are especially useful when completing the names and values of graphics properties. For example, plot(x,y,'LineStyle','-').

You can also use the suggestions to complete parameter names and options for certain functions. For example, format('shortEng').

MATLAB displays suggestions based on its current state. This includes:

  • Variables that are defined in the current workspace

  • Files and folders that are on the search path or in the current folder

  • Variables, functions, class properties, and class methods that are defined in the active document and available at the current location of the cursor

MATLAB does not complete field names of structure arrays defined only within the active file.


To use the Tab key to add multiple spaces within a statement, first add a space, and then press Tab. Otherwise, when tab completion is enabled, MATLAB attempts to complete a name.

To disable automatic suggestions and completions in the Command Window and Editor, on the Home tab, in the Environment section, click Preferences. Then, select MATLAB > Keyboard and set the options for Tab completion. Preference changes do not apply in the Live Editor.

Function Syntax Hints

As you enter a function in the Command Window, Live Editor, or Editor, syntax hints open in a pop-up window to display allowable input arguments for the function.

Function syntax hints appear for both MATLAB installed functions and functions you create. The syntax hints for MATLAB functions come from the documentation. The syntax hints for functions you create come from the function definition statement (first executable line) in the MATLAB program file. That file must be on the search path or in the current folder. For more information about adding help to the functions you create, see Add Help for Your Program.

To use function syntax hints, type a function name with an opening parenthesis. A pop-up window opens showing the basic syntax for the function. In the Live Editor, you can use the drop-down arrow to the right of the syntax to display all available syntaxes.

You can type an input for any argument that appears in blue. Enter your own input names, and not the argument names shown in the window. The displayed syntax options change based on the argument you just entered.

In the Live Editor, MATLAB displays descriptions for each argument. Optional arguments are indicated by the (optional) keyword next to the argument description.

Some function names are overloaded. That is, there are different functions with the same name that support different types of input. Overloaded functions require that you pass an object as the first input. When you specify the object name, the syntax hints update to reflect the correct version of the function, as shown. The Live Editor might not display all overloads.

Function syntax hints are suggestions only. For detailed information about a function, see the function reference page in the documentation. To open the documentation for the function, click the button to the left of the function syntax hint.

To disable function syntax hints in the Command Window and Editor, on the Home tab, in the Environment section, click Preferences. Select MATLAB > Keyboard, and then set the options for Function hints. Preference changes do not apply in the Live Editor.

Was this topic helpful?