
Scripts and Functions
The two global statements make the value assigned to GRAVITY at the
command prompt available inside the function. You can then modify
GRAVITY
interactively and obtain new solutions without editing any files.
Passing String Arguments to Functions
You can write MATLAB functions that accept string arguments without the
parentheses and quotes. That is, MATLAB interprets
fooabc
as
foo('a','b','c')
However, when you use the unquoted form, MATLAB cannot return output
arguments. For example,
legend apples oranges
creates a legend on a plot using the strings apples and oranges as labels. If
you want the
legend command to return its output arguments, then you
must use the quoted form:
[legh,objh] = legend('apples','or ange s');
In addition, you must use the quoted form if any of the arguments is not
astring.
Caution While the unquoted syntax is convenient, in some cases it can be
used incorrectly without causing MATLAB to generate an error.
Constructing String Arguments in Code
The quoted form enables you to construct string arguments within the
code. The following example processes multiple data files,
August1.dat,
August2.dat, and so on. It uses the function i nt2str,whichconvertsan
integer to a character, to build the filename:
ford=1:31
4-27
Comentarios a estos manuales