All possible grouping combination for different package
Show older comments
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
Answers (1)
Walter Roberson
on 5 Mar 2022
Edited: Walter Roberson
on 5 Mar 2022
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 Comments
Yannick Pratte
on 5 Mar 2022
Torsten
on 6 Mar 2022
Prune's answer seems promising.
Walter Roberson
on 6 Mar 2022
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.
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!