MATLAB Environment     Search    Help Desk 

Command Line Editing

These are the main aspects of command line editing in MATLAB:

Basics of Command Line Editing

These are the basic features of command line editing in MATLAB:

>> Prompt.    The prompt (>>) indicates MATLAB is ready to accept commands from you.

Arrow and Control Keys.    Use these keys to help you edit in the command line.

Arrow Key
Control Key

Recall previous line.

Recall next line.

Move back one character.

Move forward one character.
Move right one word.
Move left one word.
Move to beginning of line.
Move to end of line.
Clear line.
Delete character at cursor.
Delete character before cursor.

Delete (kill) to end of line.

Clearing the Window.    Use clc to clear the Command Window.

This does not clear the workspace, but only clears the view. After using clc, you still can use the up arrow key to see the history of the commands, one at a time.

Paging of Output.    Use more to control paging of output in the Command Window.

By default, more is off. When you set more on, a page (screenful) of output displays at one time. You then use:

To advance to the next line
Space Bar
To advance to the next page
To stop displaying the output

Suppressing Output.    If you end a line with a semicolon, MATLAB performs the computation but does not display any output.

Long Command Lines.    If a statement does not fit on one line, use an ellipsis (three periods, ...), followed by Return or Enter to indicate that the statement continues on the next line.

For example,

Interrupting a Running Program.    Press Ctrl-c at any time to interrupt a running program.

On Windows platforms, you may have to wait until an executing built-in function or MEX-file has finished its operation.

On UNIX systems, program execution terminates immediately.

Controlling Numeric Format.    The format command controls the numeric format of the values displayed on the screen.

The command affects only how numbers are displayed, not how MATLAB computes or saves them. For more control over the output format, use sprintf and fprintf.

On Windows platforms, you can change the default format by selecting Preferences from the File menu, and selecting the desired format from the General tab.

MATLAB Workspace

The MATLAB workspace contains a set of variables (named arrays) that you can manipulate from the MATLAB command line.

These are the topics for using the MATLAB workspace:

Viewing the Workspace.    Use the who and whos commands to see what is currently in the workspace.

Clearing the Workspace.    Use clear to delete all existing variables from the workspace.

Loading and Saving the Workspace.    MATLAB's save and load commands let you save the contents of the MATLAB workspace at any time during a session and then reload the data back into MATLAB during that session or a later one. load and save can also import and export text data files.

On Windows platforms, the save operation is also available by selecting Save Workspace As from the File menu. The load operation is also available by selecting Load Workspace from the File menu.

Search Path

These topics are for working with files and directory structures:

About the Search Path.    MATLAB uses a search path to find M-files. MATLAB's M-files are organized in directories or folders on your file system. Many of these directories of M-files are provided along with MATLAB, while others are available separately as toolboxes.

Search Path Rules.    If you enter the name foo at the MATLAB prompt, the MATLAB interpreter:

Looks for foo as a variable.
Checks for foo as a built-in function.
Looks in the current directory for a file named foo.m.
Searches the directories on the search path for foo.m.
If you have more than one function with the same name, only the first one in the search path order is found; other functions with the same name are considered to be shadowed and cannot be executed.

Viewing and Changing the Search Path.    Use these commands:

Default Search Path.    The default search path remembered between sessions is defined in the file pathdef.m in the directory named local on your system. pathdef executes automatically each time you start MATLAB.

On Windows platforms, you can directly edit pathdef.m with your text editor.

On UNIX workstations you may not have file system permission to edit pathdef.m. In this case, put path and addpath commands in your startup.m file to change your path defaults.

MATLAB also provides a Path Browser with a convenient interface for viewing and changing the search path. Use pathtool to start the Path Browser.

Files on the Search Path.    Use these commands to see and use files on the search path.

Current Directory.    MATLAB maintains a current directory for working with M-files and MAT-files.

On Windows platforms, the initial current directory is specified in the shortcut file you use to start MATLAB. Right-click on the shortcut file, and select Properties to change the default.

On UNIX systems, the initial current directory is the directory you are in on your UNIX file system when you invoke MATLAB.

Opening Files in MATLAB.    Use open to open files in MATLAB based on their extension as shown in the table below.

Figure file (*.fig)
Open figure in a figure window
M-file (name.m)
Open M-file name in Editor
Model (name.mdl)
Open model name in Simulink
P-file (name.p)
Open the corresponding M-file, name.m, if it exists, in the Editor
Open array name in the Array Editor (the array must be numeric); open calls openvar
Other extensions (name.custom)
Open name.custom by calling the helper function opencustom, where opencustom is a user-defined function.

[ Previous | Help Desk | Next ]