| 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:>>) indicates MATLAB is ready to accept commands from you.
Arrow and Control Keys.
Use these keys to help you edit in the command line.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:| Return |
To advance to the next line |
| Space Bar |
To advance to the next page |
| q |
To stop displaying the output |
...), 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.s = 1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 + 1/7 ...- 1/8 + 1/9 - 1/10 + 1/11 - 1/12;
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 thewho and whos commands to see what is currently in the workspace.
who gives the name
whos gives the name, size, and data type information
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:foo at the MATLAB prompt, the MATLAB interpreter:
.foo as a variable.
.foo as a built-in function.
.foo.m.
.foo.m.
path, by itself, returns the current search path.
path(s), where s is a string, sets the path to s.
addpath /home/lib and path(path,'/home/lib') both append a new rmpath /home/lib removes the path /home/lib.
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.
path to display the search path.
what to see all of the MATLAB files in a directory. With no arguments, what displays the files in the current directory.
type to see the code in a specific M-file.
edit to edit an M-file.
cd with no arguments to display the current directory.
cd with a path to change the current directory.
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.| Name |
Action |
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 |
| Variable |
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. |