No BSD License  

Highlights from
nextcombi

Be the first to rate this file! 1 Download (last 30 days) File Size: 1.26 KB File ID: #21670

nextcombi

by Dan Stowell

 

03 Oct 2008 (Updated 03 Oct 2008)

Given a set of N items, iterate over all the combinations of size R (R<N)

| Watch this File

File Information
Description

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)).

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
03 Oct 2008 John D'Errico

See my loopchoose, which does the same thing.

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=13276&objectType=FILE

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
combination Dan Stowell 22 Oct 2008 10:22:54
combinadic Dan Stowell 22 Oct 2008 10:22:54
combinatorics Dan Stowell 22 Oct 2008 10:22:54
iterate Dan Stowell 22 Oct 2008 10:22:54
combinations Dan Stowell 22 Oct 2008 10:22:54
subsets Dan Stowell 22 Oct 2008 10:22:54

Contact us at files@mathworks.com