getprctile.m (598B)
1 function [xprc,indx]=getprctile(x,prctile); 2 3 % getprctile.m function [xprc,indx]=getprctile(x,prctile); 4 % 5 % Computes the requested percentiles (e.g. 50 or 25) of the columns of x. 6 % 7 % xprc are the percentile values of the columns of x 8 % indx points to the observation so that xprc=x(indx) 9 % 10 % prctile=0 returns min; prctile=100 returns max 11 12 % Now, let's make it work on the columns of a matrix 13 [N,K]=size(x); 14 i=round(prctile/100*N); 15 if i(1)==0; i(1)=1; end; % Pass a zero to return the min 16 for k=1:K; 17 [xsort,blah]=sort(x(:,k)); 18 xprc(:,k)=xsort(i); 19 indx(:,k)=blah(i); 20 end;