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 'greater' elseif A < B 'less' end
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. Changing syntax highlighting preferences is not supported in MATLAB Online™. In the Live Editor, changing syntax highlighting color preferences is supported, but disabling syntax highlighting is not supported.
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
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.
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. Changing delimiter matching indicator preferences is not supported in the Live Editor or in MATLAB Online.
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. In MATLAB Online, the Editor behaves the same as the Live Editor.
Automatic suggestions and completions are especially useful when completing the
names and values of graphics properties. For example,
You can also use the suggestions to complete parameter names and
options for certain functions. For example,
When entering a statement that includes a function, MATLAB might suggest multiple syntaxes for the function. To view the additional syntaxes, click the arrow to the right of the syntax. You also can use the Ctrl + Down Arrow keyboard shortcut to show and hide the additional syntaxes. On macOS systems, use the Command key instead of Ctrl.
Similarly, if MATLAB suggests multiple arguments, click the arrow to the right of the argument description to view the additional arguments. You also can use the Ctrl + Alt + Right Arrow and Ctrl + Alt + Left Arrow keyboard shortcuts.
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 have MATLAB suggest and complete names only after you press the Tab key in the Live Editor, on the Home tab, in the Environment section, click Preferences. Then, select MATLAB > Keyboard and in the Suggestions and completions > Live Editor section, select Show on tab.
To disable suggestions and completions in the Command Window and Editor, in the Suggestions and completions section, clear Enable tab completion for the desired tool.
Changing suggestions and completions preferences is not supported MATLAB Online.
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 (and Editor in MATLAB Online), 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 (and Editor in MATLAB Online), 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. Then, select MATLAB > Keyboard and in the Suggestions and completions section, clear Enable function hints for the desired tool. Disabling function syntax hints is not supported in MATLAB Online.