Excel MMULT on MATLAB for different matrix dimensions.

2 views (last 30 days)
Jose Rodriguez
Jose Rodriguez on 16 Oct 2021
Edited: dpb on 16 Oct 2021
I'm trying to replicate the formula MMULT from Excel into MATLAB.
The two matrixes have different dimensions 4 x 1 and 4 x 4. Returning a product of 4 x 1
Below is an example in Excelusing MMULT
x =
Below is the MATLAB function trying to replica the above example.
The function returns C a 4 x 4 matrix when I need a 4 x 1 matrix from the product of RR times A in excel.
Thank You.
  1 Comment
Stephen on 16 Oct 2021
"I'm trying to replicate the formula MMULT from Excel into MATLAB."
Matrix multiplication is a very basic mathematical operation that has existed in MATLAB for the last forty years:
Is there a particular reason why you cannot use the inbuilt function?

Sign in to comment.

Accepted Answer

dpb on 16 Oct 2021
Edited: dpb on 16 Oct 2021
MATLAB being defined as the MATrix LABoratory follows conventional matrix algebra rules --
>> A=[0.29;-1.55;2.09;0.782];
>> R=[4/3 2/3 0 0;2/3 4/3 0 0;0 0 4/3 -2/3;0 0 -2/3 4/3];
>> C=R*A
C =
Arrays A, B are only conformable for matrix multiplication C=AB if size(A,2) == size(B,1) (number rows in B is same as number of columns in A). The size of the output array C is then size(A,1) x size(B,2).
If R is 4x4 and A 4x1, then R*A --> 4x4 * 4x1 --> 4x1
Your code above uses the "dot" operator .* which is element-wise multiplication and MATLAB silently expanded the vector to the size of the array to produce the 4x4 result.
As the above shows, all you need is the matrix multiplication operator * applied to the two variables to produce the desired result; the same as Excel implements in a much more convenient format/syntax. :)

More Answers (0)




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by