| MATLAB® | ![]() |
With respect to case, the MATLAB® language requires an exact match for variable names. For example, if you have a variable a, you cannot refer to that variable as A.
With respect to functions, filenames, objects, and classes on the search path or in the current directory, MATLAB prefers an exact match with regard to case. MATLAB runs a function if you do not enter the function name using the exact case, but displays a warning the first time you do this.
To avoid ambiguity and warning messages, always match the case exactly. It is a best practice to use lowercase only when running and naming functions. This is especially useful when you use both Microsoft® Windows® and The Open Group UNIX® platforms because their file systems behave differently with regard to case.
Note that if you use the help function, function names are shown in all uppercase, for example, PLOT, solely to distinguish them. Some functions for interfacing toSun Microsystems™ Java™ software do use mixed case and the M-file help and documentation accurately reflect that.
Examples. The directory first is at the top of the search path and contains the file A.m. If you type a instead of A, MATLAB runs A.m but issues a warning. When you type a again during that session, MATLAB runs A.m but does not show the warning.
Add the directory second after first on the search path, with the file a.m in second. The directory first contains A.m, while second contains a.m Type a. MATLAB runs a.m but displays a warning the first time you do this.
Blank spaces around operators such as -, :, and ( ), are optional, but they can improve readability. For example, MATLAB interprets the following statements the same way.
y = sin (3 * pi) / 2 y=sin(3*pi)/2
Some entries appear in different colors to help you better find elements, such as matching if/else statements. This is known as syntax highlighting. You can change the colors using preferences. Note that output does not appear with syntax highlighting, except for errors. For more information, see Colors Preferences for Desktop Tools.

You can set a preference for MATLAB to notify you about matched and unmatched delimiters. For example, when you type a parenthesis, bracket, or brace, MATLAB highlights the matched delimiter in the pair. To set these preferences, select File > Preferences > Keyboard > Delimiter Matching. This feature is also available in the Editor/Debugger.
For more information, see Delimiter Matching.
Use the Cut, Copy, Paste, Undo, and Redo features from the Edit menu when working in the Command Window. You can also access some of these features in the context menu for the Command Window.
Undo applies to some of the actions listed in Edit menu. You can undo multiple times in succession until there are no remaining actions to undo. Select Edit > Redo to reverse an undo.
If you use Enter, you cannot edit a line after entering it, even though you have not completed the flow. In that event, use Ctrl+C to end the flow, and then enter the statements again.
To enter multiple lines before running any of them, use Shift+Enter or Shift+Return after typing a line. This is useful, for example, when entering a set of statements containing keywords, such as if ... end. The cursor moves down to the next line, which does not show a prompt, where you can type the next line. Continue for more lines. Then press Enter or Return to run all of the lines.
This allows you to edit any of the lines you entered before you pressing Enter or Return.
To enter multiple functions on a single line, separate the functions with a comma ( , ) or semicolon ( ; ). Using the semicolon instead of the comma will suppress the output for the command preceding it. For example, put three functions on one line to build a table of logarithms by typing
format short; x = (1:10)'; logs = [x log10(x)]
and then press Enter or Return. The functions run in left-to-right order.
If a statement does not fit on one line, enter three periods (...) , also called dots, stops, or an ellipsis, at the end of the line to indicate it continues on the next line. Then press Enter or Return. Continue typing the statement on the next line. You can repeat the ellipsis to add a line break after each line until you complete the statement. When you finish the statement, press Enter or Return.
For items in single quotation marks, such as strings, you must complete the string in the line on which it was started. For example, completing a string as shown here
headers = ['Author Last Name, Author First Name, ' ... 'Author Middle Initial']
results in
headers = Author Last Name, Author First Name, Author Middle Initial
MATLAB produces an error when you do not complete the string, as shown here:
headers = ['Author Last Name, Author First Name, ... Author Middle Initial'] ??? headers = ['Author Last Name, Author First Name, ... Error: Missing variable or function.
Note that MATLAB ignores anything appearing after the ... on a line, and continues processing on the next line. This effectively creates a comment out of the text following the ... on a line. For more information, see Commenting Out Part of a Statement.
Use the arrow, tab, and control keys on your keyboard to recall, edit, and reuse functions you typed earlier. For example, suppose you mistakenly enter
rho = (1+ sqt(5))/2
Because you misspelled sqrt, MATLAB responds with
Undefined function or variable 'sqt'.
Instead of retyping the entire line, press the up arrow
key. The previously
typed line is redisplayed. Use the left arrow key to move the cursor,
add the missing r, and press Enter or Return to run the line. Repeated use of the
up arrow key recalls earlier lines, from the current and previous
sessions. Using the up arrow key, you can recall any line maintained
in the Command History window.
Similarly, specify the first few characters of a line you entered previously and press the up arrow key to recall the previous line. For example, type the letters plo and then press the up arrow key. This displays the last line that started with plo, as in the most recent plot function. Press the up arrow key again to display the next most recent line that began with plo, and so on. Then press Enter or Return to run the line. This feature is case sensitive.
If the up arrow key moves the cursor up but does not recall previous lines, clear the accessibility preference. For more information, see Accessibility.
Another way to view and access commands from the current and previous sessions of MATLAB is with the Command History window — see Command History Window.
MATLAB helps you automatically complete the names of these items as you type them in the Command Window:
Function or model on the search path or in the current directory
Filename or directory
Variable, including structures, in the current workspace
Handle Graphics® property for figure in the current workspace
Type the first few characters of the item name and then press the Tab key. To use tab completion, you must have the tab completion preference for the Command Window selected. For details, see Keyboard Preferences.
Tab completion is also available in the Editor/Debugger, but there are some slight differences in usage. See Tab Completion in the Editor.
These examples demonstrate how to use tab completion in the Command Window:
This example illustrates a basic use for tab completion. After creating a variable, costs_march, type
costs
and press Tab. MATLAB automatically completes the name of the variable, displaying
costs_march
Then complete the statement, adding any arguments, operators, or options, and press Return or Enter to run it. In this example, if you just press Enter, MATLAB displays the contents of costs_march. If MATLAB does not complete the name costs_march but instead moves the cursor to the right, you do not have the preference set for tab completion. If MATLAB displays No Completions Found, costs_march does not exist in the current workspace.
You can use tab completion anywhere in the line, not just at the beginning. For example, if you type
a = cost
and press Tab, MATLAB completes costs_march. You can also select co or position the cursor after co and press Tab to complete costs_march.
If there is more than one name that starts with the characters you typed, when you press the Tab key, MATLAB displays a list of all names that start with those characters. For example, type
cos
and press Tab. MATLAB displays

The resulting list of possible completions includes the variable name you created, costs_march, but also includes functions that begin with cos, including cosets from the Communications Toolbox™ software, if it is installed on the system and on the search path in MATLAB. MATLAB completes variable names in the currently selected workspace, and the names of functions and models on the search path or in the current directory.
Continue typing to make your entry unique. For example, type the next character, such as t in the example. MATLAB selects the first item in the list that matches what you typed, in this case, costs_march. Press Enter (or Return) or Tab to select that item, which completes the name at the prompt. In the example, MATLAB displays costs_march at the prompt. Add any arguments, and press Enter again to run the statement.
You can navigate the list of possible completions using up and down arrow keys, and Page Up and Page Down keys. You can clear the list without selecting anything by pressing Escape. Note that the list of possible completions might include items that are not valid commands, such as private functions.
Narrowing Completions Shown. You can narrow the list of completions shown by typing a character and then pressing Tab if the Command Window preference Tab key narrows completions is selected. This is particularly useful for large lists. For example, type cam and press Tab to see the possible completions. There is a scroll bar with the list because there are too many completions to be seen at once.

Type p and press Tab again. MATLAB narrows the list, showing only all possible camp completions.

Continue narrowing the list in the same way. For the above example, type o and press Tab to further narrow the list. Press Enter or Return to select an item, which completes the name at the prompt.
Tab completion works for directories and filenames in MATLAB functions. For example, type
edit d:/
and press Tab.
MATLAB displays the list of directories and files in d, from which you can choose one. For example, type
mym
and press Tab.
MATLAB displays
edit d:/mymfiles/
where mymfiles is the only directory on your d drive whose name begins with mym. Continue using tab completion to display and complete directory names or filenames until you finish the edit statement.
Tab completion for directories and filenames is not supported for functions you write.
For structures in the current workspace, after the period separator, press Tab. For example, type
mystruct.
and press Tab to display all fields of mystruct. If you type a structure and include the start of a unique field after the period, pressing Tab completes that structure and field entry.
For example, type
mystruct.n
and press Tab, which completes the entry mystruct.name, where mystruct contains no other fields that begin with n.
Complete property names for figures in the current workspace using tab completion, as in this graphics example. Here, f is a figure. Type
set(f, 'pap
and press Tab. MATLAB displays

Select a property from the list. For example, type
u
and press Enter. MATLAB completes the property, including the closing quote.
set(f, 'paperunits'
Continue adding to the statement, as in this example
set(f, 'paperunits', 'c
and press Tab. MATLAB automatically completes the property
set(f, 'paperUnits', 'centimeters'
because centimeters is the only possible completion.
Following is the list of arrow and control keys that serve as shortcuts for using the Command Window. In addition to these shortcut keys (sometimes called hot keys), you can use shortcuts for menu items, which you can view on the menus, as well as general desktop shortcuts described in Keyboard Shortcuts. If you select the Emacs (MATLAB standard) preference for key bindings (see Command Window Key Bindings for an explanation), you can also use the Ctrl+key combinations shown in the table.
Key or Mouse Action for Windows Preference | Control Key for MATLAB standard (Emacs) Preference | Key or Mouse Action for Macintosh Preference | Operation |
|---|---|---|---|
| Ctrl+P |
| Recall previous line — for details, see Recalling Previous Lines. See also Command History Window, which is a log of previously used functions, and Keeping a Session Log. With the Accessibility preference selected, moves the cursor up a line when it is above
the prompt. In that event, use Ctrl+
|
| Ctrl+N |
| Recall next line — for details, see Recalling Previous Lines. Works only after using the up arrow or Ctrl+P. With the Accessibility preference selected, moves the cursor down
a line when it is above the prompt. In that event, use Ctrl+
|
Ctrl+Home | None | Home | Move to top of Command Window. |
Ctrl+End | None | End | Move to end of Command Window. |
| None | None | Cmd+Home | Move cursor and scroll to top of Command Window. |
| None | None | Cmd+End | Move cursor and scroll to end of Command Window. |
| None | None | Shift+Cmd+Home | Select to top of Command Window. |
| None | None | Shift+Cmd+End | Select to end of Command Window. |
| Ctrl+B |
| Move back one character. |
| Ctrl+F |
| Move forward one character. |
Ctrl+
| None | Option+
| Move left one word. |
Ctrl+
| None | Option+
| Move right one word. |
Home | Ctrl+A | Cmd+
| Move to beginning of current statement. With key bindings for Macintosh platforms, move to beginning of current line. |
End | Ctrl+E | Cmd+
| Move to end of current statement. With key bindings for Macintosh platforms, move to end of current line. |
Esc | Ctrl+U | Esc | Clear the command line when cursor is at the command line. Otherwise, move cursor to command line. |
Delete | Ctrl+D | Forward Delete | Delete character after cursor. |
Backspace | Ctrl+H | Delete | Delete character before cursor. |
None | Ctrl+K | None | Cut contents (kill) from cursor to end of current line. |
Insert | None | None | Change to overwrite mode from insert mode, or change to insert mode from overwrite mode. View current mode in the status bar: OVR is gray for insert mode. In overwrite mode, what you type replaces existing text and the cursor is a wide block. (Not supported on Macintosh platforms.) |
Double-click | None | Double-click | Select current word. To select additional words, hold mouse after second click and continue dragging left or right. |
| None | None | Shift+Option+
| Select to previous word. |
| None | None | Shift+Option+
| Select to next word. |
Triple-click | None | None | Select current line. To select additional lines, hold mouse after second click and continue dragging up or down. |
Shift+Home | None | Shift+Cmd+
| Select from cursor to beginning of statement. With key bindings for Macintosh platforms, select to beginning of line. |
Shift+End | None | Shift+Cmd+
| Select from cursor to end of statement. With key bindings for Macintosh platforms, select to end of line. |
Enter in selection | None | None | Append selection to statement at command line and execute it. |
Ctrl+Enter in hyperlink | None | Ctrl+Enter in hyperlink | Open hyperlink displayed in Command Window. For example, in the hyperlink of an error message, opens the file in the Editor/Debugger at that line number. |
To look at or copy information in the Command Window that is above the command line (>> prompt), use the mouse and scroll bar, key combinations such as Ctrl+Home, and search features. By default, the up and down arrow keys recall statements so you cannot use them to move the cursor when it is above the command line.
To use the up and down arrow keys to move the cursor when it is above the command line, select File > Preferences > Command Window, and select the Accessibility preference.
![]() | Running Functions and Programs, and Entering Variables | Controlling Output | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |