Matrix Dimensions must Agree

1 visualización (últimos 30 días)
Muhammad Hamza
Muhammad Hamza el 27 de Sept. de 2021
Editada: Walter Roberson el 27 de Sept. de 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?

Respuesta aceptada

Walter Roberson
Walter Roberson el 27 de Sept. de 2021
Editada: Walter Roberson el 27 de Sept. de 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.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by