I need to generate the complete set of combinations obtained combining three different subset:
I guess this could be further optimized but this generates you AllComb
:
H=3;
L=4;
a = combnk(1:H+L-1, H);
b = cumsum([a(:,1) diff(a,[],2) - 1],2);
H=2;
L=3;
c = combnk(1:H+L-1, H);
d = cumsum([c(:,1) diff(c,[],2) - 1],2);
H=2;
L=4;
e = combnk(1:H+L-1, H);
f = cumsum([e(:,1) diff(e,[],2) - 1],2);
u=[];
for k=1:10
u=vertcat(u,d);
end
u=sortrows(u,[1 2]);
v=[];
for k=1:6
v= vertcat(v,f);
end
w= [u,v];
v=[];
for k=1:20
v= vertcat(v,w);
end
u=[];
for k=1:60
u = vertcat(u,b);
end
u=sortrows(u,[1 2 3]);
AllComb= [u,v];
Here b,d
and f
are your 3 sets. Then i loop over the numbers of permutation in d
and f
and replicate them so that all possibilities are constructed. One of them is sorted and then i write them in a new matrix w
. THis process is repeated with Set A (b
) and this new constructed matrix. Resulting in the end in AllComb
.