Getting Started with MATLAB   Search    Help Desk 

The MATLAB Environment

The MATLAB environment includes both the set of variables built up during a MATLAB session and the set of disk files containing programs and data that persist between sessions.

The Workspace

The workspace is the area of memory accessible from the MATLAB command line. Two commands, who and whos, show the current contents of the workspace. The who command gives a short list, while whos also gives size and storage information.

Here is the output produced by whos on a workspace containing results from some of the examples in this book. It shows several different MATLAB data structures. As an exercise, you might see if you can match each of the variables with the code segment in this book that generates it.

To delete all the existing variables from the workspace, enter

save Commands

The save commands preserve the contents of the workspace in a MAT-file that can be read with the load command in a later MATLAB session. For example

saves the entire workspace contents in the file August17th.mat. If desired, you can save only certain variables by specifying the variable names after the filename.

Ordinarily, the variables are saved in a binary format that can be read quickly (and accurately) by MATLAB. If you want to access these files outside of MATLAB, you may want to specify an alternative format.

-ascii

Use 8-digit text format.

-ascii -double

Use 16-digit text format.

-ascii -double -tabs  

Delimit array elements with tabs.

-v4

Create a file for MATLAB version 4.

-append

Append data to an existing MAT-file.

When you save workspace contents in text format, you should save only one variable at a time. If you save more than one variable, MATLAB will create the text file, but you will be unable to load it easily back into MATLAB.

The Search Path

MATLAB uses a search path, an ordered list of directories, to determine how to execute the functions you call. When you call a standard function, MATLAB executes the first M-file function on the path that has the specified name. You can override this behavior using special private directories and subfunctions.

The command

shows the search path on any platform. On PCs and Macs, choose Set Path from the File menu to view or modify the path.

Disk File Manipulation

The commands dir, type, delete, and cd implement a set of generic operating system commands for manipulating files. This table indicates how these commands map to other operating systems.

MATLAB

MS-DOS

UNIX

VAX/VMS

dir

dir

ls

dir

type

type

cat

type

delete

del or erase

rm

delete

cd

chdir

cd

set default

For most of these commands, you can use pathnames, wildcards, and drive designators in the usual way.

The diary Command

The diary command creates a diary of your MATLAB session in a disk file. You can view and edit the resulting text file using any word processor. To create a file called diary that contains all the commands you enter, as well as MATLAB's printed output (but not the graphics output), enter

To save the MATLAB session in a file with a particular name, use

To stop recording the session, use

Running External Programs

The exclamation point character ! is a shell escape and indicates that the rest of the input line is a command to the operating system (or to the Finder on the Macintosh). This is quite useful for invoking utilities or running other programs without quitting MATLAB. On VMS, for example,

invokes an editor called edt for a file named magik.m. When you quit the external program, the operating system returns control to MATLAB.



[ Previous | Help Desk | Next ]