All possible grouping combination for different package

5 ビュー (過去 30 日間)
Yannick Pratte
Yannick Pratte 2022 年 3 月 5 日
コメント済み: Walter Roberson 2022 年 3 月 6 日
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

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 3 月 5 日
編集済み: Walter Roberson 2022 年 3 月 5 日
S = {'A', 'B', 'C', 'D', 'E'}
S = 1×5 cell array
{'A'} {'B'} {'C'} {'D'} {'E'}
Group1 = nchoosek(S, 3)
Group1 = 10×3 cell array
{'A'} {'B'} {'C'} {'A'} {'B'} {'D'} {'A'} {'B'} {'E'} {'A'} {'C'} {'D'} {'A'} {'C'} {'E'} {'A'} {'D'} {'E'} {'B'} {'C'} {'D'} {'B'} {'C'} {'E'} {'B'} {'D'} {'E'} {'C'} {'D'} {'E'}
and in each case, Group2 is setdiff(S) and the corresponding elements of group 1.
  3 件のコメント
Walter Roberson
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 ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by