Operation on 3 dimension matrix

Hi I have two 3-dimension matrices A(N,M,P) and B(M,N,P). I want to calculate the multiplication along two dimensions, that is
for ii=1:P
C(:,:,ii) = A(:,:,ii)*B(:,:,ii);
end
Is there any solution to achieve the above computation without for loop?
Thanks
Rui

Respuestas (2)

Image Analyst
Image Analyst el 24 de Jun. de 2017
How about this:
C = A .* B;

1 comentario

Image Analyst
Image Analyst el 24 de Jun. de 2017
My answer is for element by element multiplication, like masking an image or something, not row times column "matrix" multiplication. Can you confirm that you want matrix multiplication, where C(1,2,1) = sum(A(1,:,1) .* B(:,2,1), and not something like C(1,2,1) = A(1,2,1)*B(1,2,1)?

Iniciar sesión para comentar.

Jan
Jan el 24 de Jun. de 2017
Editada: Jan el 24 de Jun. de 2017

0 votos

Why do you want to do this without a loop? The main work is spent with tha matrix multiplication. Even a vectorized version cannot reduce this work.
But a parallelization can distribute the job. Do you have the Parallel Processing Toolbox? Then use parfor.
You can try these alternative tools:

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 24 de Jun. de 2017

Comentada:

el 24 de Jun. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by