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개)

카테고리

Help CenterFile Exchange에서 Exploration and Visualization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by