0001 function [y, i] = sg_datasample(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 input = varargin;
0013 n_inpput = length(input);
0014 data = input{1};
0015 k = input{2} ;
0016 N = length(data);
0017
0018 if k > N
0019 error('sg_datasample: number of samples limited to size of data');
0020 end
0021
0022 if n_inpput == 4
0023 if strcmp(input{3},'replace') && ~input{4}
0024 ii = (1:N);
0025 ord = rand(size(data(:,1)));
0026 [junk, j] = sort(ord);
0027 i = ii(j(1:k));
0028 y = data(i,:);
0029 end
0030 else
0031 i = randi(N,k,1);
0032 y = data(i,:);
0033 end
0034