MATLAB: Generating a subset of specific of unique 3 groups out of 84

nchoosk

Hi all, I've the following indices: indices = nchoosek ([1:9], 3)
indices =
1 2 3
1 2 4
1 2 5
1 2 6
1 2 7
1 2 8
1 2 9
1 3 4
1 3 5
1 3 6
1 3 7
1 3 8
1 3 9
1 4 5
1 4 6
1 4 7
1 4 8
1 4 9
1 5 6
1 5 7
1 5 8
1 5 9
1 6 7
1 6 8
1 6 9
1 7 8
1 7 9
1 8 9
2 3 4
2 3 5
2 3 6
2 3 7
2 3 8
2 3 9
2 4 5
2 4 6
2 4 7
2 4 8
2 4 9
2 5 6
2 5 7
2 5 8
2 5 9
2 6 7
2 6 8
2 6 9
2 7 8
2 7 9
2 8 9
3 4 5
3 4 6
3 4 7
3 4 8
3 4 9
3 5 6
3 5 7
3 5 8
3 5 9
3 6 7
3 6 8
3 6 9
3 7 8
3 7 9
3 8 9
4 5 6
4 5 7
4 5 8
4 5 9
4 6 7
4 6 8
4 6 9
4 7 8
4 7 9
4 8 9
5 6 7
5 6 8
5 6 9
5 7 8
5 7 9
5 8 9
6 7 8
6 7 9
6 8 9
7 8 9
where each row of the above 84 rows gives a specific value as shown: C1=reshape(C_IA,size(indices,1) ,[])
C1 =
26.5871 - 0.0000i
25.3748 + 0.0000i
29.1875 - 0.0000i
27.8822 - 0.0000i
27.9279 - 0.0000i
29.8068 - 0.0000i
20.1088 + 0.0000i
28.9700 + 0.0000i
31.4866 - 0.0000i
30.7709 - 0.0000i
29.1391 - 0.0000i
29.5271 - 0.0000i
28.7390 - 0.0000i
32.2309 - 0.0000i
26.0994 - 0.0000i
31.6562 - 0.0000i
27.2213 + 0.0000i
19.1752 + 0.0000i
29.0539 + 0.0000i
31.9886 + 0.0000i
28.7934 + 0.0000i
26.9325 + 0.0000i
30.8589 + 0.0000i
26.5858 + 0.0000i
27.5174 + 0.0000i
31.3600 + 0.0000i
29.4643 - 0.0000i
28.1896 - 0.0000i
20.4114 + 0.0000i
25.9653 - 0.0000i
29.2150 - 0.0000i
29.3785 + 0.0000i
25.1405 - 0.0000i
25.2144 - 0.0000i
19.9587 - 0.0000i
27.7516 + 0.0000i
27.5817 + 0.0000i
30.9471 - 0.0000i
21.9452 + 0.0000i
25.7818 - 0.0000i
27.0898 - 0.0000i
25.6516 + 0.0000i
27.9703 - 0.0000i
29.8913 - 0.0000i
28.7567 + 0.0000i
26.5974 - 0.0000i
27.8911 + 0.0000i
28.2247 + 0.0000i
30.4570 - 0.0000i
32.3383 - 0.0000i
23.6659 - 0.0000i
26.0332 - 0.0000i
24.4511 - 0.0000i
31.6553 - 0.0000i
28.5011 + 0.0000i
28.2660 - 0.0000i
25.6020 - 0.0000i
30.5952 + 0.0000i
23.9412 + 0.0000i
18.3079 - 0.0000i
27.3033 + 0.0000i
29.0838 + 0.0000i
29.8749 - 0.0000i
28.0912 + 0.0000i
19.2981 + 0.0000i
23.3627 - 0.0000i
29.4325 - 0.0000i
31.1372 - 0.0000i
22.5496 - 0.0000i
27.3350 - 0.0000i
28.2363 + 0.0000i
34.0017 + 0.0000i
28.1177 - 0.0000i
32.8989 + 0.0000i
28.2460 - 0.0000i
26.2227 - 0.0000i
24.6639 - 0.0000i
25.9026 + 0.0000i
30.5478 - 0.0000i
25.5483 - 0.0000i
29.4994 - 0.0000i
31.3045 + 0.0000i
31.9083 - 0.0000i
32.6127 - 0.0000i
I would like to generate 3 different group of numbers in one time (where each row represent a number) so that all the three groups has unique (not repeated) numbers. i.e. If the 1st generated group was : 1 2 3 (which has a value of 26.5871 then the 2nd group must be any three numbers from 1 to 9 except 1 2 3 (let's say 2nd generated group was: 4 5 6 which has a value of 19.2981 ) then the 3rd generated group must be any number from 1 to 9 except all previously selected numbers (any 3 numbers except 1,2,3,4,5,6) hence we have 3rd group is: 7 8 9 which has a value of 32.6127 so, the expected result of my example is : 26.5871 19.2981 32.6127
I need to do this for all different cases (and not for only the above case), i.e to generate all possible ways of dividing up the numbers from 1 to 9 into three groups with three numbers in each group. The total number of these is 9!/3!/3!/3! = 1680 different result. (the above Example gives only one result out of those 1680 result that i need)
another 2nd example for clarity, if one combination out of the 1680 combinations was: 7 8 9 4 5 6 1 2 3 then i expect to get C1(84,:) and C1(65,:) and C1(1,:)
any help?
P.S. I've already got the 1680 rows combinations but don't know how to map those to my 84 result of C1

Best Answer

Suppose [i1,i2,i3,i4,i5,i6,i7,i8,i9] is one of your combinations. Then you can reference the corresponding three values in C1 using the three indices k1, k2, and k3 in the following:
n = 9;
k1 = n*(n-1)*(n-2)/6-(n-i1)*(n-1-i1)*(n-2-i1)/6-(n-i2)*(n-1-i2)/2-(n-i3);
k2 = n*(n-1)*(n-2)/6-(n-i4)*(n-1-i4)*(n-2-i4)/6-(n-i5)*(n-1-i5)/2-(n-i6);
k3 = n*(n-1)*(n-2)/6-(n-i7)*(n-1-i7)*(n-2-i7)/6-(n-i8)*(n-1-i8)/2-(n-i9);
and get
C1(k1), C1(k2), C1(k3)
(This formula is in fact valid for any n, not just n = 9.)