Script that create all combination in a matrix

3 ビュー (過去 30 日間)
Lucas S
Lucas S 2020 年 6 月 19 日
コメント済み: Lucas S 2020 年 6 月 19 日
Hello,
I have a matrix of 3 elements (3 columns).
A | B | C
Each elements can take 4 values (0, 1, 2, 3). Is there a function or a way to test all possibilities and complete the matrix with all possibilities ? So 3^4 possibilities.
0|1|2
0|1|3
...
...
Thanks
Edit : I miss an information, in my case elements can have same values so i need to take in consideration :
0 | 0 | 0
1 | 1 | 1
0 | 0 | 2
...
  2 件のコメント
KSSV
KSSV 2020 年 6 月 19 日
Read about nchoosek.
Lucas S
Lucas S 2020 年 6 月 19 日
編集済み: Lucas S 2020 年 6 月 19 日
Thanks it works for all differents values combination ! But is there also a way to generate combination when elements can have same values too like the in the edit of the post ?

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

採用された回答

Rik
Rik 2020 年 6 月 19 日
Yet another possible solution:
A=0:3;B=0:3;C=0:3;
[A_,B_,C_]=ndgrid(A,B,C);
combs=[A_(:),B_(:),C_(:)];
  1 件のコメント
Lucas S
Lucas S 2020 年 6 月 19 日
Thanks !

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

その他の回答 (1 件)

madhan ravi
madhan ravi 2020 年 6 月 19 日
  1 件のコメント
Lucas S
Lucas S 2020 年 6 月 19 日
編集済み: Lucas S 2020 年 6 月 19 日
Thanks it works for all differents values combination ! But is there also a way to generate combination when elements can have same values too like the in the edit of the post ?

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

カテゴリ

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