# Thread: MATLAB: Vectorized arithmetic operations

1. ## MATLAB: Vectorized arithmetic operations

Hi

.* is an array operator (element-by-element operator). Now, if a=2 and x=[1 2], then why am I allowed to calculate a.*x? I mean, it is an element-by-element operator, so it should give me an error.

Furthermore, * is a matrix-operator (according to Support - Code Vectorization Guide). If that is the case, then why am I allowed to calculate the product x*a? Only a*x should be allowed.

I hope you will help me by shedding some light on this.

Best,
Niles.

2. I believe that answer to this is that MATLAB treats single element arrays as a "scalar" value therefore .* and * are equivalent if either one of the components is scalar.

Regards Elbarto

3. Originally Posted by elbarto
I believe that answer to this is that MATLAB treats single element arrays as a "scalar" value therefore .* and * are equivalent if either one of the components is scalar.

Regards Elbarto
Thanks. Does that mean that MATLAB itself transposes the vector a in the case x*a?

4. Originally Posted by Niles_M
Thanks. Does that mean that MATLAB itself transposes the vector a in the case x*a?
No a is a scalar and for it makes no difference if you have a*x or x*a

if a=[1,2] x=[2,3] a and b are non-compliant matrices and neither a*x or x*a will execute without throwing an error (but a.*x and x.*a will execute properly).

CB