Generate nchoosek vectors line-by-line

2 views (last 30 days)
Howard Wilton
Howard Wilton on 28 May 2022
Answered: Bjorn Gustavsson on 28 May 2022
I would like to interate through combinations according to the code,
combos = nchoosek(1:512,6);
for c = 1:size(combos,1)
% code
end
However, the number of combinations, 2.4295e+13, is too big. Is there a way to generate the combinations line-by-line? I have no intention of running code for every single one, but I would like to index and get a specific combination for that index.

Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 28 May 2022
There are loads of nchoosek functions available on the file exchange: nchoosek. Some of those should help you with this. I recall using versions by Jos, Bruno Luong, or/and Jan.
HTH

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!