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

Answers (2)

How about this:
C = A .* B;

1 Comment

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)?

Sign in to comment.

Jan
Jan on 24 Jun 2017
Edited: Jan on 24 Jun 2017
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:

Categories

Asked:

on 24 Jun 2017

Commented:

on 24 Jun 2017

Community Treasure Hunt

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

Start Hunting!