SAMPLE Random sampling of points from a data-set CALL: s = sample(data,m,R) s = sampled selection from data, size m x D data = data matrix, size N x D (D = # dimensions) m = sampling size R = 0 sampling without replacement 1 sampling with replacement (default) SAMPLE(DATA,M,R) selects a random sample of M data points from the multivariate data-set in the matrix DATA. Example: data = wnormrnd(0,1,500,3); s = sample(data,100,0)
GUI to Kernel Density Estimator. | |
GUI to Kernel Density Estimator in two dimensions. |
001 function s=sample(A,m,r) 002 %SAMPLE Random sampling of points from a data-set 003 % 004 % CALL: s = sample(data,m,R) 005 % 006 % s = sampled selection from data, size m x D 007 % data = data matrix, size N x D (D = # dimensions) 008 % m = sampling size 009 % R = 0 sampling without replacement 010 % 1 sampling with replacement (default) 011 % 012 % SAMPLE(DATA,M,R) selects a random sample of M data points from the 013 % multivariate data-set in the matrix DATA. 014 % 015 % Example: 016 % data = wnormrnd(0,1,500,3); 017 % s = sample(data,100,0) 018 % 019 020 % History: 021 % revised pab dec2003 022 % changed ind generation to avoid dependence on stats-toolbox 023 % revised pab 10.12.1999 024 % - faster sampling 025 % by CB kdetools 026 027 if nargin<2, 028 error('Incorrect number of function parameters'); 029 end; 030 if nargin<3 |isempty(r) 031 r=1; 032 end 033 034 [n d]=size(A); 035 036 if m>n & r==0, 037 error('Requested sample size too large'); 038 end; 039 040 if m==n & r==0, 041 s=A; 042 return; 043 end; 044 045 if r==0, % Sample without replacement. 046 ind = randperm(n); 047 else % sample with replacement 048 ind = ceil(n*rand(m,1)); 049 end 050 s=A(ind(1:m),:); 051
Comments or corrections to the WAFO group