nextcombi

Version 1.0.0.0 (712 Bytes) by Dan Stowell
Given a set of N items, iterate over all the combinations of size R (R<N)
430 Downloads
Updated 3 Oct 2008

No License

Given a set of N items, we want to do something with all possible subsets of that set which have size K. This method iterates over those subsets in a deterministic fashion. Unlike "nchoosek" (which can return a list of all such combinations) the list of possible combinations is never generated in memory, meaning it should be possible to apply this to quite large K.

Example: to print all combinations of 6C3:

a = 1:3;
while a
disp(a);
a = nextcombi(6, a);
end

The complexity of nextcombi is O(N), so the iteration of all combinations should be O(N * nchoosek(N,K)).

Cite As

Dan Stowell (2024). nextcombi (https://www.mathworks.com/matlabcentral/fileexchange/21670-nextcombi), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2007a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Data Type Identification in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0.0