The MATLAB Working Environment
The following table summarizes the main components of the MATLAB working environment.
Tool | Description |
---|
Command History | This presents a history of the functions introduced in the Command Window and allows you to copy and execute them (see the lower right part of Figure ). |
Command Window | This is the window in which you execute MATLAB commands (see the central part of Figure ). |
Workspace | This shows the present contents of the workspace and allows you to make changes to it (see the upper right part of Figure ). |
Help | This allows you to search and read the documentation for the complete family of MATLAB products. |
Start button | This runs tools and gives you access to documentation for all MathWorks products currently installed on your computer (Figure ). |
Figure shows the screen in which you enter MATLAB programs. This is MATLABs primary work environment.
Any MATLAB commands are entered in the Command Window to the right of the user input prompt >> and the response will appear in the lines immediately below, after pressing Enter . After the command has been executed the user input prompt will reappear, allowing you to enter more commands (Figure ).
If the result of a command is not assigned to a variable, MATLAB will return the response using the expression ans = , as shown at the beginning of Figure , which is subsequently used as input for an exponential.
To execute a MATLAB command, simply press Enter once the command is written. If at the end of the input we put a semicolon, the program will execute the command and keep the result in memory ( Workspace ), but it will not display the result on screen (see the first input in Figure ). The input prompt >> will then reappear to indicate that you can enter a new command.
Like the C programming language, MATLAB is case sensitive; for example, Sin( x ) is not the same as sin( x ). The names of all built-in functions begin with a lowercase character. There should be no spaces in the names of commands, variables or functions. In other cases, spaces are ignored, and they can be used to make the input more readable. Multiple entries can be entered in the same command line by separating them with commas, pressing Enter at the end of the last entry (see Figure ). If you use a semicolon at the end of one of the entries in the line, its corresponding output will not be displayed.
Descriptive comments can be entered in a command input line by starting them with the % symbol. When you run the input, MATLAB ignores the comment and processes the rest of the code (see Figure ).
To simplify the process of entering script to be evaluated by the MATLAB interpreter (via the Command Window prompt), you can use the arrow keys. For example, if you press the up arrow key once, you will recover the last entry you submitted. If you press the up key twice, you will recover the penultimate entry you submitted, and so on.
If you type a sequence of characters in the input area and then press the up arrow key, you will recover the last entry you submitted that begins with the specified string.
Commands entered during a MATLAB session are temporarily stored in the buffer ( Workspace ) until you end the session, at which time they can be permanently stored in a file or are permanently lost.
Below is a summary of the keys that can be used in MATLABs input area (command line), together with their functions:
Up arrow (Ctrl-P) | Retrieves the previous entry. |
Down arrow (Ctrl-N) | Retrieves the following entry. |
Left arrow (Ctrl-B) | Moves the cursor one character to the left. |
Right arrow (Ctrl-F) | Moves the cursor one character to the right. |
CTRL-left arrow | Moves the cursor one word to the left. |
CTRL-right arrow | Moves the cursor one word to the right. |
Home (Ctrl-A) | Moves the cursor to the beginning of the line. |
End (Ctrl-E) | Moves the cursor to the end of the current line. |
Escape | Clears the command line. |
Delete (Ctrl-D) | Deletes the character indicated by the cursor. |
Backspace | Deletes the character to the left of the cursor. |
CTRL-K | Deletes (kills) the current line. |
The command clc clears the command window, but does not delete the contents of the work area (the contents remain in the memory).