Here's a brute force generation of all combinations. Memory usage is more of a bottleneck than processing time, so I wrote it with for-loops.
Note that storing all combinations may not be the best approach to address your underlying use case.
Set sz = 100 to match your vector size; beware of 50 million rows.
sz = 10;
a = (1:sz)';
b = a + sz;
c = b + sz;
res = NaN(sz^3*(sz-1)/2,4);
iCounter = 0;
for ai = 1:(numel(a)-1),
for aj = (ai+1):numel(a),
for bi = 1:sz,
for ci = 1:sz,
iCounter = iCounter + 1;
res(iCounter,:) = [a(ai) a(aj) b(bi) c(ci)];
end
end
end
end
4 Comments
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/332801-obtain-every-possible-combination-in-array#comment_441623
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/332801-obtain-every-possible-combination-in-array#comment_441623
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/332801-obtain-every-possible-combination-in-array#comment_441629
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/332801-obtain-every-possible-combination-in-array#comment_441629
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/332801-obtain-every-possible-combination-in-array#comment_441631
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/332801-obtain-every-possible-combination-in-array#comment_441631
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/332801-obtain-every-possible-combination-in-array#comment_441638
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/332801-obtain-every-possible-combination-in-array#comment_441638
Sign in to comment.