- An example of a row vector
>> a=[1 2 3] a = 1 2 3

- An example of a column vector
>> a=[1;2;3] a = 1 2 3

- If you need to multiply, square, divide, etc. any array you need to proceed the operation by a '.'.
>> n=0:5 n = 0 1 2 3 4 5 >> n^2 ??? Error using = > ^ Matrix must be square. >> n.^2 ans = 0 1 4 9 16 25

- Be careful when multiplying two arrays.
>> a=[1 2 3] a = 1 2 3 >> b=[4;5;6] b = 4 5 6 >> a*b ans = 32 >> a'.*b ans = 4 10 18

Since`a`is a row vector and`b`is a column vector, if you use`a*b`you will have performed a dot product. On the other had if you want to multiply every element in`a`by every element in`b`to generate a new vector, then you need to transpose one of the two vectors by using`'`and then multiply the two vectors using`.*`.

Copyright © 2004, Aly El-Osery

Last Modified 2005-10-27