Please help with this multiplication problem

Hi folks,
We know that a 1 x n array times an m x 1 array gives an n x m matrix. I have a 1 x n x r matrix and a m x 1 x r matrix. Is there a way to do the multiplication of the two such that it gives me an m x n x r 3D matrix?
Thanks!
Jianwei

2 件のコメント

Matt J
Matt J 2025 年 3 月 5 日
We know that a 1 x n array times an m x 1 array gives an n x m matrix.
That is not correct. Perhaps you mean an mx1 array times a 1xn array gives an mxn matrix.
Jianwei Tu
Jianwei Tu 2025 年 3 月 5 日
Yep, exactly. My bad.

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

 採用された回答

Matt J
Matt J 2025 年 3 月 5 日
編集済み: Matt J 2025 年 3 月 5 日

0 投票

You can multiply directly. Example:
[m,n,r]=deal(3,4,2);
A=rand(m,1,r);
B=rand(1,n,r);
C=A.*B;
whos A B C
Name Size Bytes Class Attributes A 3x1x2 48 double B 1x4x2 64 double C 3x4x2 192 double

2 件のコメント

Jianwei Tu
Jianwei Tu 2025 年 3 月 5 日
編集済み: Jianwei Tu 2025 年 3 月 5 日
Great!
Been using the .* for a while, but did not realize you could use it such way.
Thanks!
Matt J
Matt J 2025 年 3 月 5 日
You're welcome, but please Accept-click the answer to indicate that it worked.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

リリース

R2024b

質問済み:

2025 年 3 月 5 日

コメント済み:

2025 年 3 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by