3 matrix product without dimension error

1 visualización (últimos 30 días)
Amirhosein hematyar
Amirhosein hematyar el 2 de Jul. de 2021
Comentada: Yazan el 2 de Jul. de 2021
Hi all
I have a x with 2*72 dimensions and want to product the x(i)'*W*x(j) that W is inv(cov(x)) and 72*72.
I write it:
H=zeros(n,n);
for i=1:n
for j=1:n
H(i,j)=x(:,i)'*W*x(:,j);
H(j,i)=H(i,j);
end
end
but i receive dimension errors
please help me.

Respuestas (2)

Walter Roberson
Walter Roberson el 2 de Jul. de 2021
x is 2x72. indexing one column of it gives 2x1. Transpose gives 1x2. That does not match the 72x72 of W.

Yazan
Yazan el 2 de Jul. de 2021
Editada: Yazan el 2 de Jul. de 2021
You can multiply the matrices directly without a loop.
% random matrices
x = randn(2, 72); y = randn(72, 72);
% multiplication, result is 2-by-72
res = x*y;
  2 comentarios
Walter Roberson
Walter Roberson el 2 de Jul. de 2021
result would be 2x72
Yazan
Yazan el 2 de Jul. de 2021
Corrected, thanks!

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by