All possible grouping combination for different package
显示 更早的评论
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 个)
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 个评论
Yannick Pratte
2022-3-5
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!