| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about 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, file names, objects, and classes on the search path or in the current folder, 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 UNIX[1] 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 folder 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 folder second after first on the search path, with the file a.m in second. The folder 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
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.
Press the Esc (escape) key to clear everything you entered on the current line.
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 statements on multiple lines before running any of them, use Shift+Enter or Shift+Return after typing a statement on a line. The cursor moves down to the next line, which does not show a prompt, where you can type the next statement. Continue for more lines. Then press Enter or Return to run all of the lines. This allows you to edit any of the statements before you pressing Enter or Return. This is an example:
>> a=1 % Press Shift+Enter to advance without executing this statement. b=2 % Press Shift+Enter to advance without execution. You can edit this or the above line. c=a+b % Press Enter to execute all three statements.
MATLAB executes all three lines and returns the following:
a =
1
b =
2
c =
3
>>When you enter a paired keyword statement on multiple lines, such as for and end, you do not need to use Shift+Enter. You can use the typical process of pressing Enter after each line in the set to advance to the next line. MATLAB executes the keyword statement after complete it on the last line. For example
>> for r=1:5 % Press Enter. MATLAB advances a line where you continue the paired keyword statement. a=pi*r^2 % Press Enter. MATLAB advances a line where you continue the paired keyword statement. end % Press Enter to execute the paired keyword statement.
MATLAB executes all three lines and returns the following:
a = 3.141592653589793 a = 12.566370614359172 a = 28.274333882308138
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.
Assuming you have not changed the default keyboard shortcuts for the arrow, tab, and control keys, you can recall, edit, and reuse functions you typed earlier by using these keys. 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 keys do not behave as documented here, check the actions currently assigned to them, as described in Identifying Keyboard Shortcuts.
Another way to view and access commands from the current and previous sessions of MATLAB is with the Command History window — see Using the Command History Window.
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, and so by default, you cannot use these keys 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, customize the keyboard shortcuts for the Cursor Up and Cursor Down actions in the Keyboard Shortcuts preferences. See also, Customizing Keyboard Shortcuts.
[1] UNIX is a registered trademark of The Open Group in the United States and other countries.
![]() | Running Functions and Programs, and Entering Variables | Assistance While Entering Statements | ![]() |

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 |