function xf=fractile(x,f)
% xf=fractile(x,f)
% Compute the f fractile of x. E.g. if f=0.85, it computes the 85th
% percentile of x. Disregards NaNs.
%
% (c) Simon de Szoeke
% 2008-10-28
% Anyone may use this function for free. Republishing or licensing it for 
% compensation is prohibited by the author.

ii=isfinite(x);
if sum(ii)==0
    xf=NaN;
else
    xs=sort(x(ii));
    xf=xs(min(max(1,round(f*sum(ii))),sum(ii)));
end