annotate toolboxes/FullBNT-1.0.7/KPMtools/subsets1.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function sub_s=subsets1(s,k)
Daniel@0 2 % SUBSETS1 creates sub-sets of a specific from a given set
Daniel@0 3 % SS = subsets1(S, k)
Daniel@0 4 %
Daniel@0 5 % S is the given set
Daniel@0 6 % k is the required sub-sets size
Daniel@0 7 %
Daniel@0 8 % Example:
Daniel@0 9 %
Daniel@0 10 % >> ss=subsets1([1:4],3);
Daniel@0 11 % >> ss{:}
Daniel@0 12 % ans =
Daniel@0 13 % 1 2 3
Daniel@0 14 % ans =
Daniel@0 15 % 1 2 4
Daniel@0 16 % ans =
Daniel@0 17 % 1 3 4
Daniel@0 18 % ans =
Daniel@0 19 % 2 3 4
Daniel@0 20 %
Daniel@0 21 % Written by Raanan Yehezkel, 2004
Daniel@0 22
Daniel@0 23 if k<0 % special case
Daniel@0 24 error('subset size must be positive');
Daniel@0 25 elseif k==0 % special case
Daniel@0 26 sub_s={[]};
Daniel@0 27 else
Daniel@0 28 l=length(s);
Daniel@0 29 ss={};
Daniel@0 30 if l>=k
Daniel@0 31 if k==1 % Exit condition
Daniel@0 32 for I=1:l
Daniel@0 33 ss{I}=s(I);
Daniel@0 34 end
Daniel@0 35 else
Daniel@0 36 for I=1:l
Daniel@0 37 ss1=subsets1(s([(I+1):l]),k-1);
Daniel@0 38 for J=1:length(ss1)
Daniel@0 39 ss{end+1}=[s(I),ss1{J}];
Daniel@0 40 end
Daniel@0 41 end
Daniel@0 42 end
Daniel@0 43 end
Daniel@0 44 sub_s=ss;
Daniel@0 45 end