function val = prctile1(in,t)
%
% function val = prctile1(in,t)
%
% this function computes an approximation to the Matlab statistics
% toolbox "prctile" function.  Returns a value that is approximately
% t percent of the input function with t quantized to 1..100 percent
%
[bincnt bincent]=hist(in,100);
bsum=sum(bincnt(:));
ind=find(cumsum(bincnt)>=t*bsum/100);
if length(ind)>1
  val=bincent(ind(1));
else
  if t < 50
    val=bincent(1);
  else
    val=bincent(end);
  end
end

