Mercurial > hg > mauch-mirex-2010
view _FullBNT/KPMtools/subsets1.m @ 9:4ea6619cb3f5 tip
removed log files
author | matthiasm |
---|---|
date | Fri, 11 Apr 2014 15:55:11 +0100 |
parents | b5b38998ef3b |
children |
line wrap: on
line source
function sub_s=subsets1(s,k) % SUBSETS1 creates sub-sets of a specific from a given set % SS = subsets1(S, k) % % S is the given set % k is the required sub-sets size % % Example: % % >> ss=subsets1([1:4],3); % >> ss{:} % ans = % 1 2 3 % ans = % 1 2 4 % ans = % 1 3 4 % ans = % 2 3 4 % % Written by Raanan Yehezkel, 2004 if k<0 % special case error('subset size must be positive'); elseif k==0 % special case sub_s={[]}; else l=length(s); ss={}; if l>=k if k==1 % Exit condition for I=1:l ss{I}=s(I); end else for I=1:l ss1=subsets1(s([(I+1):l]),k-1); for J=1:length(ss1) ss{end+1}=[s(I),ss1{J}]; end end end end sub_s=ss; end