Mercurial > hg > camir-aes2014
annotate toolboxes/FullBNT-1.0.7/KPMtools/partitionData.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
rev | line source |
---|---|
wolffd@0 | 1 function varargout = partitionData(Ndata, varargin) |
wolffd@0 | 2 % PARTITIONDATA Partition a vector of indices into random sets |
wolffd@0 | 3 % [a,b,c,...] = partitionData(N, 0.3, 0.2, 0.5, ...) |
wolffd@0 | 4 % |
wolffd@0 | 5 % Examples: |
wolffd@0 | 6 % [a,b,c]=partitionData(105,0.3,0.2,0.5); |
wolffd@0 | 7 % a= 1:30, b=32:52, c=52:105 (last bin gets all the left over) |
wolffd@0 | 8 |
wolffd@0 | 9 Npartitions = length(varargin); |
wolffd@0 | 10 perm = randperm(Ndata); |
wolffd@0 | 11 %perm = 1:Ndata; |
wolffd@0 | 12 ndx = 1; |
wolffd@0 | 13 for i=1:Npartitions |
wolffd@0 | 14 pc(i) = varargin{i}; |
wolffd@0 | 15 Nbin(i) = fix(Ndata*pc(i)); |
wolffd@0 | 16 low(i) = ndx; |
wolffd@0 | 17 if i==Npartitions |
wolffd@0 | 18 high(i) = Ndata; |
wolffd@0 | 19 else |
wolffd@0 | 20 high(i) = low(i)+Nbin(i)-1; |
wolffd@0 | 21 end |
wolffd@0 | 22 varargout{i} = perm(low(i):high(i)); |
wolffd@0 | 23 ndx = ndx+Nbin(i); |
wolffd@0 | 24 end |
wolffd@0 | 25 |