Development Environment |
Running Functions and Entering Variables
Entering Statements at the Command Line Prompt
The prompt (>>
) in the Command Window indicates that MATLAB is ready to accept input from you. When you see the >> prompt, you can enter a variable or run a function. This prompt and your input are known as the command line.
For example, to create A
, a 3-by-3 matrix, type
When you press the Enter or Return key after typing the line, MATLAB responds with
To run a function, type the function including all arguments and press Return or Enter. MATLAB displays the result. For example, type
If you want to enter multiple lines before running, use Shift+Enter or Shift+Return after each line until the last. Then press Enter or Return to run all of the lines.
The K>>
prompt in the Command Window indicates that MATLAB is in debug mode. For more information, see Editing and Debugging M-Files.
Evaluating a Selection
To run a selection in the Command Window, make the selection, and then right-click and select Evaluate Selection from the context menu. Alternatively, after making a selection, press Enter or Return. You cannot evaluate a selection while MATLAB is busy, for example, running an M-file.
Opening a Selection
You can open a function, file, variable, or Simulink model from the Command Window. Select the name in the Command Window, and then right-click and select Open Selection from the context window. This runs the open
function for the item you selected so that it opens in the appropriate tool:
.fig
) open in a figure window
See open
for details. If no file exists to work with the selected item, Open selection calls edit
.
Hyperlinks to Run Functions
Use matlab:
to create a hyperlink for specified text, which runs the specified function when clicked. For example, typing
When the user clicks the link "Generate magic square
", MATLAB runs magic(4)
. You can use the disp
or the fprintf
functions with this feature.
Running One Process
In MATLAB, you can only run one process at a time. If MATLAB is busy running one function, any commands you issue will be buffered in a queue. The next command will run when the previous one finishes.
Opening the Command Window | Controlling Input and Output |