
functions element-wise. The
l
l
e
e
n
n
g
g
t
t
h
h of the above vector is obtained via the
following command:
Matlab’s command:
>> length(y)
Matlab’s response:
ans =
5
Note that
l
l
e
e
n
n
g
g
t
t
h
h is a build-in function that given a vector, it returns its
length. Since the result of this function is not stored in a user-defined
variable, Matlab saves the result in the
a
a
n
n
s
s variable. If it is need to save the
vector’s length to a variable named
Y
Y
l
l
e
e
n
n
g
g
t
t
h
h the command would be:
Matlab’s command:
>> Ylength=length(y)
Matlab’s response:
Ylength =
5
With Matlab, vectors can be easily multiplied by a scalar and added or
subtracted with other vectors of similar length. Moreover, a scalar can be
added or subtracted to or from a vector and smaller vectors can be used to
construct larger ones. All these operations are performed element-wise. Note
that each vector represents a variable. Some examples follow:
Matlab’s command:
>> a=[-1 2 -3]; b=[2 1 2];
>> c=5*a
Matlab’s response:
c =
-5 10 -15
Comments:
An element-by-element multiplication of vector
a
a by 5.
Komentáře k této Příručce