Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Matlab array multiply

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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)].
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading