nextcombi
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
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |