3D Matrix Multiplication

60 ビュー (過去 30 日間)
Rahul Marwaha
Rahul Marwaha 2021 年 2 月 24 日
コメント済み: Masoud Aminzadeh 2023 年 8 月 6 日
Hi I have created two large matrices of which I have reshaped to create the following:
A = 3x1x4 double
B = 3x3x4 double
C = B * A ????
I was wondering how I could multiply each 3x3 matrix from B with each 3x1 matrix from A? The aim is to create a new 3x1x4 matrix in the end. Note: I don't have R2020b so don't have access to the pagemtimes function.
Any help is greatly appreciated, thanks!
  1 件のコメント
Masoud Aminzadeh
Masoud Aminzadeh 2023 年 8 月 6 日
use pagewise function

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

採用された回答

the cyclist
the cyclist 2021 年 2 月 24 日
編集済み: the cyclist 2021 年 2 月 24 日
You can do it straightforwardly with a for loop:
% Some made-up input data
A = rand(3,1,4);
B = rand(3,3,4);
[mA,nA,pA] = size(A);
[mB,nB,pB] = size(B);
C = zeros(mB,nA,pA);
for np = 1:pA
C(:,:,np) = B(:,:,np) * A(:,:,np);
end
  1 件のコメント
Rahul Marwaha
Rahul Marwaha 2021 年 2 月 25 日
Thanks, that worked perfectly!

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 2 月 24 日
  1 件のコメント
James Tursa
James Tursa 2021 年 2 月 24 日

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

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by