How to multiplay matrices in different dimensions?

108 ビュー (過去 30 日間)
Lilja Dahl
Lilja Dahl 2019 年 6 月 6 日
コメント済み: Lilja Dahl 2019 年 6 月 10 日
I would like to multiply a 3D matrice with a 2D matrice.
  1 件のコメント
Jan
Jan 2019 年 6 月 6 日
Then do this. Remember that this operation is not defined mathematically, so you have to explain which result you want. Do you mean a matrix multiplication, or an elementwise product?

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

採用された回答

Jan
Jan 2019 年 6 月 6 日
編集済み: Jan 2019 年 6 月 6 日
Perhaps:
a = rand(2,2,3);
b = [2, 2; 4, 4]
% Elementwise - auto-expanding since R2016b:
r = a .* b
% Matrix multiplication:
r = zeros(2, 2, 3);
for k = 1:3
r(:, :, k) = a(:, :, k) * b;
end
If the later is wanted, you can vectorize the code or use some tools from the FileExchange to avoid the loop.
  1 件のコメント
Lilja Dahl
Lilja Dahl 2019 年 6 月 10 日
Thank you so much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by