Skip to content

Instantly share code, notes, and snippets.

@avanwieringen
Created October 27, 2011 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avanwieringen/1319401 to your computer and use it in GitHub Desktop.
Save avanwieringen/1319401 to your computer and use it in GitHub Desktop.
Combinations
function [ comb ] = combinations( set, length )
comb = [];
for i=1:(size(set,2) - length + 1)
if(length > 1)
chcombs = combinations(set(i+1:end), length - 1);
for i_c=1:size(chcombs, 1)
comb(end + 1,:) = [set(i) chcombs(i_c,:)];
end
else
comb(end + 1,:) = set(i);
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment