MATLAB Answers

Mulitplying 3D matrix by 3D matrix - result being 4D.

1 ビュー (過去 30 日間)
Ryan Motley
Ryan Motley 2021 年 8 月 3 日
コメント済み: Ryan Motley 2021 年 8 月 3 日
I have a 3x3x512 matrix and I am trying to perform a multiplication with a 3x512x512 matrix whereby the result is that each page of the second matrix (3x512) is multiplied by all 512 pages of the first matrix seperately.
Ideally I would end up with a 3x512x512x512 matrix in the end. I've done this with a foor loop (see below) but I was wondering if there was a way to do it without the loop and just by matrix multiplication.
for i = 1:512
for j = 1:512
result(:,:,i,j) = matrix1(:,:,i)*matrix2(:,:,j);
end
end
EDIT
Alternatively, is there a way to do this with cells with the result being a 512x512 cell of 3x512 doubles? Would this be any faster than doing the whole thing as a for loop?
Thanks

採用された回答

James Tursa
James Tursa 2021 年 8 月 3 日
result = pagemtimes(matrix1,reshape(matrix2,3,512,1,512));
  1 件のコメント
Ryan Motley
Ryan Motley 2021 年 8 月 3 日
Thank you! Works perfectly!

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by