diff options
Diffstat (limited to 'sourcecodes/bnt-master/SLP/misc/subsets1.m')
| -rw-r--r-- | sourcecodes/bnt-master/SLP/misc/subsets1.m | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/SLP/misc/subsets1.m b/sourcecodes/bnt-master/SLP/misc/subsets1.m new file mode 100644 index 00000000..ca2bf46c --- /dev/null +++ b/sourcecodes/bnt-master/SLP/misc/subsets1.m @@ -0,0 +1,45 @@ +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 |
