Graphics Programs Reference
In-Depth Information
where they begin and end. In the Command Window of MATLAB 5 and earlier
versions, however, you have to hunt for matching delimiters by hand.
Wrong delimiters: Using parentheses in place of brackets, or vice versa, and
so on.
CAUSE:
SOLUTION: Remember the basic rules about delimiters in MATLAB.
Parentheses are used bothfor grouping arithmetic expressions and for enclo-
sing inputs to a MATLAB command, an M-file, or an inline function. They
are also used for referring to an entry in a matrix. Square brackets are used
for defining vectors or matrices. Single quote marks are used for defining
strings.
EXAMPLE:
The following illustrates what can happen if you don't follow these rules:
>> X = -1:.01:1;
>> X[1]
??? X[1]
|
Error: Missing operator, comma, or semicolon.
>> A=(0,1,2)
??? A=(0,1,2)
|
Error: Error: ")" expected, "," found.
These examples are fairly straightforward to understand; in the first case,
X(1) was intended, and in the second case, A=[0,1,2] was intended. But
here's a trickier example:
>> sin 3
ans =
0.6702
Here there's no error message, but if one looks closely, one discovers that
MATLAB has printed out the sine of 51 radians, not of 3 radians!! The ex-
planation is as follows: Any time a MATLAB command is followed by a space
and then an argument to the command (as in the construct clear x ), the
argument is always interpreted as a string. Thus MATLAB has inter-
preted 3 not as the number 3, but as the string '3' ! And sure enough, one
discovers:
Search WWH ::




Custom Search