Digital Signal Processing Reference
In-Depth Information
E.2 Entering data i
nto M
ATLAB
Data can be entered in the M
ATLAB
as a scalar quantity, a row or column vector,
and a multidimensional array. In each case, both real and complex numbers can
be entered. As required in other high-level languages, there is no need to declare
the type of a variable before assigning data to it. For example, variable
a
can
be assigned the value (6
+
j8) by typing the following command:
>>a=6+j*8
On the execution of the above command, M
ATLAB
returns the following
answer:
a = 6.0000 + 8.0000i
In the above command, we did not allocate any value to
j
, yet M
ATLAB
recognized it as a complex operator with value j
2
=
1
.
There is a whole range
of special words that are used by M
ATLAB
either as the name of functions or
variables. These include
pi
,
i
,
j
,
Inf
,
NaN
,
sin
,
cos
,
tan
,
exp
, and
rem
.
Type
help elfun
to list the names that are used by M
ATLAB
to specify the
built-in functions and variables. The value of any of these special words can be
changed by assigning a new value to it. For example,
>> sin = 1
allocates the value of 1 to the variable
sin
. The M
ATLAB
definition of
the trigonometric sine is overwritten by our command. To check the cur-
rent status of the runtime environment of M
ATLAB
, type
whos
at the
prompt:
>> whos
M
ATLAB
returns the following answer:
Name Size Bytes Class
a 1x1 16 double array (complex)
sin 1x1 8 double array
Grand total is 2 elements using 24 bytes
Alternatively, the command
who
can also be used to list the name of defined
variables in the M
ATLAB
runtime environment. The command
who
does not
provide additional details such as the size and class of each variable. In the
preceding discussions, we overwrote the
sin
function and allocated a value of
1 to it. Consequently, we cannot access the M
ATLAB
built-in function
sin
to evaluate the sine of an angle. To clear our definition of
sin
, we can use the
following command:
>> clear sin
Search WWH ::
Custom Search