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 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.
whos Name Size Bytes Class A 4x4 128 double array D 5x3 120 double array M 10x1 3816 cell array S 1x3 442 struct array h 1x11 22 char array n 1x1 8 double array s 1x5 10 char array v 2x5 20 char array Grand total is 471 elements using 4566 bytes.To delete all the existing variables from the workspace, enter
clearThe
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
save August17thsaves 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.
pathshows the search path on any platform. On PCs and Macs, choose Set Path from the File menu to view or modify the path. 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.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
diaryTo save the MATLAB session in a file with a particular name, use
diary filenameTo stop recording the session, use
diary offThe 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,
!edt magik.minvokes an editor called
edt
for a file named magik.m
. When you quit the external program, the operating system returns control to MATLAB.