Graphics Programs Reference
In-Depth Information
Interacting with the Operating System
This section is somewhat advanced, as is the following chapter. On a first
reading, you might want to skip ahead to Chapter 9.
Calling External Programs
MATLAB allows you to run other programs on your computer from its com-
mand line. If you want to enter UNIX or DOS file manipulation commands,
you can use this feature as a convenience to avoid opening a separate window.
Or you may want to use MATLAB to graphthe output of a program writ-
ten in a language suchas FORTRAN or C. For large-scale computations, you
may wishto combine routines written in another programming language with
routines you write in MATLAB.
Thesimplestwaytorunanexternalprogramistotypeanexclamationpoint
atthebeginningofaline,followedbytheoperatingsystemcommandyouwant
to run. For example, typing !dir on a Windows system or !ls -l on a UNIX
system will generate a more detailed listing of the files in the current working
directorythantheMATLABcommand dir .InChapter3wedescribed dir and
other MATLAB commands, such as cd , delete , pwd , and type , that mimic
similar commands from the operating system. However, for certain operations
(suchas renaming a file) you may need to run an appropriate command from
the operating system.
If you use the operating system interface in an M-file that you want to run
on either a Windows or UNIX system, you should use the test functions
ispc and/or isunix to set off the appropriate commands for each type of
system, for example, if isunix; ...; else; ...; end . If you need to
distinguishbetween different versions of UNIX (Linux, Solaris, etc.), you can
use computer instead of isunix .
The output from an operating system command preceded by ! can only be
displayed to the screen. To assign the output of an operating system com-
mand to a variable, you must use dos or unix . Thougheachis only docu-
mentedtoworkforitsrespectiveoperatingsystem,incurrentversionsofMAT-
LAB they work interchangeably. For example, if you type [stat, data]=
dos('myprog 0.5 1000') , the program myprog will be run withcommand
line arguments 0.5 and 1000 and its “standard output” (which would nor-
mallyappearonthescreen)willbesavedasastringinthevariable data .(The
variable stat will contain the exit status of the program you run, normally 0
Search WWH ::




Custom Search