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

Réponses (2)

Image Analyst
Image Analyst le 24 Juin 2017

0 votes

How about this:
C = A .* B;

1 commentaire

Image Analyst
Image Analyst le 24 Juin 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)?

Connectez-vous pour commenter.

Jan
Jan le 24 Juin 2017
Modifié(e) : Jan le 24 Juin 2017

0 votes

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:

Catégories

Question posée :

le 24 Juin 2017

Commenté :

le 24 Juin 2017

Community Treasure Hunt

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

Start Hunting!

Translated by