comparison toolboxes/FullBNT-1.0.7/KPMtools/subsets1.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function sub_s=subsets1(s,k)
2 % SUBSETS1 creates sub-sets of a specific from a given set
3 % SS = subsets1(S, k)
4 %
5 % S is the given set
6 % k is the required sub-sets size
7 %
8 % Example:
9 %
10 % >> ss=subsets1([1:4],3);
11 % >> ss{:}
12 % ans =
13 % 1 2 3
14 % ans =
15 % 1 2 4
16 % ans =
17 % 1 3 4
18 % ans =
19 % 2 3 4
20 %
21 % Written by Raanan Yehezkel, 2004
22
23 if k<0 % special case
24 error('subset size must be positive');
25 elseif k==0 % special case
26 sub_s={[]};
27 else
28 l=length(s);
29 ss={};
30 if l>=k
31 if k==1 % Exit condition
32 for I=1:l
33 ss{I}=s(I);
34 end
35 else
36 for I=1:l
37 ss1=subsets1(s([(I+1):l]),k-1);
38 for J=1:length(ss1)
39 ss{end+1}=[s(I),ss1{J}];
40 end
41 end
42 end
43 end
44 sub_s=ss;
45 end