Could anyone tell me how to different combinations with respect to 6 users on the same coding.

1 次查看(过去 30 天)
If there are 4 users I want to combine users into groups under the conditions:
  1. condition 1->users present in one group should not be present in other group.
  2. condition 2->users need to form different combinations of groups, since there are 4 users. Say for example, (12,34) can be one combination. The next one can be (13,24), and other one can be (14,23).
code
unused_rows=1:4
while ~isempty(unused_rows)
N_UE_rows=2;
rows=unused_rows(randsample(length(unused_rows),N_UE_rows))
[~,idx]=find(ismember(unused_rows,rows))
unused_rows(idx)=[]
end
The above code works, but I can get only one combination of results. Can anyone help me to get the output of all three combinations.

采纳的回答

Image Analyst
Image Analyst 2018-3-23
If you have the Statistics and Machine Learning Toolbox, try this:
>> c = combnk(1:6, 4)
c =
3 4 5 6
2 4 5 6
2 3 5 6
2 3 4 6
2 3 4 5
1 4 5 6
1 3 5 6
1 3 4 6
1 3 4 5
1 2 5 6
1 2 4 6
1 2 4 5
1 2 3 6
1 2 3 5
1 2 3 4
  1 个评论
Prabha Kumaresan
Prabha Kumaresan 2018-3-23
thanks.for the code
c = combnk(1:4,2)
c =
3 4
2 4
2 3
1 4
1 3
1 2
could you tell me how to group the combinations such that number present in one combination should not be present in other combination.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by