What is the difference between multiplications * and .* in 2 arrays in matlab.
E.g. a=[1 2 3], b=[4 5 6] Error using * when trying a * b = c c=[4 10 18]
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches theyour text number of rows in the
second matrix. To operate on each element of the matrix individually, use TIMES (.*) for elementwise multiplication.
>Solution :
- The first multiplication is used for normal mathematical matrix multiplication where you need the number of columns in the first matrix to match the number of rows in the second one. In your example you may try making b a column array first, then try multiplying it like this:
a=[1 2 3];
b=[4 5 6]';
c=a*b
- .* is an operation that involves multiplying each element from an array with the corresponding element from the other array, meaning in your example c=[a(1)*b(1) a(2)*b(2) a(3)*b(3)].