How to get all combinations of PRODUCTS between two array elements?

9 ビュー (過去 30 日間)
Nadatimuj
Nadatimuj 2022 年 6 月 9 日
コメント済み: Voss 2022 年 6 月 10 日
Hi,
Let's say I have two arrays.
A =[5 6 8 9 7];
B= [3 4 5];
I need all combinations of elements of A* elements of B. for examle, 5*3, 5*4, 5*5, 6*3, 6*4,...and so on Thanks.

採用された回答

Voss
Voss 2022 年 6 月 9 日
A = [5 6 8 9 7];
B = [3 4 5];
A.*B.'
ans = 3×5
15 18 24 27 21 20 24 32 36 28 25 30 40 45 35
  2 件のコメント
Nadatimuj
Nadatimuj 2022 年 6 月 10 日
Thanks!
Voss
Voss 2022 年 6 月 10 日
You're welcome!

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 6 月 9 日
A(:).*B(:).'
If you can guarantee that both are row vectors then either
A.'. * B
or
A .* B.'
The result will be a 2d array, length() of one by length() of the other.

カテゴリ

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

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by