Matrix Dimensions must Agree
2 views (last 30 days)
Show older comments
Muhammad Hamza
on 27 Sep 2021
Edited: Walter Roberson
on 27 Sep 2021
When I used the following command on MATLAB I got the error
>> D1d = D_pca(:,1)*eigvects(:,1)
Error using *
Inner matrix dimensions must agree.
But when I added the ' at the end then the error disappeared.
>> D1d = D_pca(:,1)*eigvects(:,1)'
D1d =
6.1500 -2.0524
-1.9502 0.6508
-8.6987 2.9029
4.4990 -1.5014
I need to help with why this happened? What is the reason behind it? What does the comma do?
0 Comments
Accepted Answer
Walter Roberson
on 27 Sep 2021
Edited: Walter Roberson
on 27 Sep 2021
Your D_pca has 4 rows and an unknown number of columns.
Your eigvects has 2 rows and an unknown number of columns.
D_pca(:,1)*eigvects(:,1)
is a request to use algebraic matrix multiplication (inner product) between a 4 x 1 vector and a 2 x 1 vector. But for inner product, the number of columns in the first operand (which is 1 in this case) must match the number of rows in the second operand (which is 2 in this case).
When you ask D_pca(:,1)*eigvects(:,1)' then you are asking to have inner product between a 4 x 1 matrix and transpose of a 2 x 1 vector, which is 4 x 1 * 1 x 2, and then the "inner dimensions" match so you can multiply and produce a 4 x 2 result.
0 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!