All possible grouping combination for different package
5 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I want to group items in different packages and have all possible combinations. On the other hand, there must not be repetition with the same elements in a different order for the same package.
There are X elements that I would like to divide into Y groups with all possible combinations. For example, for X=5 elements: A, B, C, D, E and Y=2 groups, this should be as follow:
Group 1, Group 2
Combination 1: {A, B, C} , {D, E}
Combination 2: {A, B, D} , {C, E}
Combination 3: {A, D, E} , {B, C}
…
However, all grouping combination with the same element should be avoided, such as A,B,C or A,C,B.
Thanks
0 件のコメント
回答 (1 件)
Walter Roberson
2022 年 3 月 5 日
編集済み: Walter Roberson
2022 年 3 月 5 日
S = {'A', 'B', 'C', 'D', 'E'}
Group1 = nchoosek(S, 3)
and in each case, Group2 is setdiff(S) and the corresponding elements of group 1.
3 件のコメント
Torsten
2022 年 3 月 6 日
Prune's answer seems promising.
Walter Roberson
2022 年 3 月 6 日
https://www.mathworks.com/matlabcentral/fileexchange/24133-set-partition gives code to partition into a fixed number of non-empty sets. In itself, it is not designed for fixed set sizes. Perhaps @Bruno Luong has an adaptation for that purpose.
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!