Borrar filtros
Borrar filtros

Multiply 4D array with 2D array without a for loop

3 visualizaciones (últimos 30 días)
Julian Büchel
Julian Büchel el 20 de Nov. de 2017
Respondida: KL el 20 de Nov. de 2017
I want to compute this:
for i=1:4
f = f+ norm(reshape(i2k(S(:,:,1,i) .* C,[1,2]) - b(:,:,1,i),[sz^2 1]) ,2)^2;
end
Without a for loop. Because we square the norm we can do that:
sum(abs(i2k(S(:,:,1,:) .* C,[1,2])-b(:,:,1,:)).^2);
But I get an error when I do this
S(:,:,1,:) .* C,[1,2]
Can somebody tell me how this is done correctly?

Respuestas (1)

KL
KL el 20 de Nov. de 2017
Try this,
bsxfun(@times,S(:,:,1,:),C)
but remember, the result you'll get as a 3D matrix.

Categorías

Más información sobre Multidimensional Arrays 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