function X=xval(cf, P) % xval(cf, P) gives the x value of the given cumulative function at the % given value of P. F() inverse. if iscf(cf)==0 error('invalid cumulative function') end if min(P)<0 | max(P)>1 error('invalid P value') end P=P(:)'; X=zeros(size(P)); x=xvals(cf); p=pvals(cf); if isdiscrt(cf)==0 for i=1:length(P), j=round(P(i)*length(x)+0.5); if j>length(x) j=length(x); end if P(i)>=p(j) while j=p(j) if j<=length(p)-10 if P(i)>p(j+10) j=j+10; else j=j+1; end else j=j+1; end end X(i)=x(j); else j=j-1; while j>0 & P(i)10 if P(i)0 j=j+1; elseif j==0 if P(i)>p(1) j=1; else j=0; end end X(i)=x(j+1); end end else for i=1:length(P), index=find(p>=P(i)); X(i)=x(index(1)); end end