Graphics Programs Reference
In-Depth Information
if the program runs without error.) If the output of your program consists only
of numbers, then
str2num(data)
will yield a row vector containing those
numbers. You can also use
sscanf
to extract numbers from the string
data
;
type
help sscanf
for details.
➱
A program you run with
!
,
dos
,or
unix
must be in the current
directory or elsewhere in the path your system searches for
executable files; the MATLAB path will not be searched.
If you are creating a program that will require extensive communication
between MATLAB and an external FORTRAN or C program, then compiling
the external program as a
MEX file
will be more efficient than using
dos
or
unix
. To do so, you must write some special instructions into the external
program and compile the program from within MATLAB using the command
mex
. This will result in a file with the extension
.mex
that you can run from
within MATLAB just as you would run an M-file. The advantage is that a
compiled program will generally run muchfaster than an M-file, especially
when loops are involved.
The instructions you need to write into your program to compile it with
mex
are described in
MATLAB
:
Using MATLAB
:
External Interfaces/API
in
the Help Browser and in the “MEX, API, & Compilers” section of the web site
http://www.mathworks.com/support/tech-notes
Look for the page entitled “Is there a tutorial for creating MEX-files with
emphasisonCMEX-files?”Theinstructionsdependtosomeextentonwhether
your program is written in FORTRAN or C, but they are not hard to learn if
youalreadyknowoneoftheselanguages.MATLABversion6alsoprovidesthe
MATLABJava Interface
, which enables you to create and access Java objects
from within MATLAB.
File Input and Output
In Chapter 3 we discussed how to use
save
and
load
to transfer variables
betweentheWorkspaceandadiskfile.Bydefaultthevariablesarewrittenand
read in MATLAB's own binary format, which is signified by the file extension
.mat
. You can also read and write text files, which can be useful for sharing
data withother programs. With
save
you type
-ascii
at the end of the line
to save numbers as text rounded to 8 digits, or
-ascii -double
for 16-digit
accuracy. With
load
the data are assumed to be in text format if the file name
does not end in
.mat
. This provides an alternative to importing data with
dos
Search WWH ::
Custom Search