Operation on 3 dimension matrix
Ältere Kommentare anzeigen
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
Antworten (2)
Image Analyst
am 24 Jun. 2017
How about this:
C = A .* B;
1 Kommentar
Image Analyst
am 24 Jun. 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:
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!