Graphics Programs Reference
In-Depth Information
>> char(51)
ans =
3
In other words, in MATLAB's encoding scheme, the string '3' is stored as the
number 51 , which is why sin 3 (or also sin('3') ) produces as output the
sine of 51 radians.
Braces or curly brackets are used less often than either parentheses or
square brackets and are usually not needed by beginners. Their main use
is withcell arrays. One example to keep in mind is that if you want an M-file
to take a variable number of inputs or produce a variable number of outputs,
then these are stored in the cell arrays varargin and varargout , and braces
are used to refer to the cells of these arrays. Similarly, case is sometimes used
withbraces in the middle of a switch construct. If you want to construct a
vector of strings, then it has to be done with braces, since brackets when ap-
plied to strings are interpreted as concatenation.
EXAMPLE:
>> {'a', 'b'}
ans =
'a' b'
>> ['a', 'b']
ans =
ab
Improper use of arithmetic symbols.
CAUSE:
SOLUTION: When you encounter a syntax error, review your input line carefully for
mistakes in typing.
EXAMPLE:
If the user, intending to compute 2 times 4, inadvertently switches the
symbols, the result is
>>2-*4
??? 2-*4
|
Error: Expected a variable, function, or constant,
found "*".
Search WWH ::




Custom Search