Operation on 3 dimension matrix
Afficher commentaires plus anciens
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
le 24 Juin 2017
How about this:
C = A .* B;
1 commentaire
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)?
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
En savoir plus sur Resizing and Reshaping Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!