annotate _FullBNT/KPMtools/partitionData.m @ 9:4ea6619cb3f5 tip

removed log files
author matthiasm
date Fri, 11 Apr 2014 15:55:11 +0100
parents b5b38998ef3b
children
rev   line source
matthiasm@8 1 function varargout = partitionData(Ndata, varargin)
matthiasm@8 2 % PARTITIONDATA Partition a vector of indices into random sets
matthiasm@8 3 % [a,b,c,...] = partitionData(N, 0.3, 0.2, 0.5, ...)
matthiasm@8 4 %
matthiasm@8 5 % Examples:
matthiasm@8 6 % [a,b,c]=partitionData(105,0.3,0.2,0.5);
matthiasm@8 7 % a= 1:30, b=32:52, c=52:105 (last bin gets all the left over)
matthiasm@8 8
matthiasm@8 9 Npartitions = length(varargin);
matthiasm@8 10 perm = randperm(Ndata);
matthiasm@8 11 %perm = 1:Ndata;
matthiasm@8 12 ndx = 1;
matthiasm@8 13 for i=1:Npartitions
matthiasm@8 14 pc(i) = varargin{i};
matthiasm@8 15 Nbin(i) = fix(Ndata*pc(i));
matthiasm@8 16 low(i) = ndx;
matthiasm@8 17 if i==Npartitions
matthiasm@8 18 high(i) = Ndata;
matthiasm@8 19 else
matthiasm@8 20 high(i) = low(i)+Nbin(i)-1;
matthiasm@8 21 end
matthiasm@8 22 varargout{i} = perm(low(i):high(i));
matthiasm@8 23 ndx = ndx+Nbin(i);
matthiasm@8 24 end
matthiasm@8 25