function [cum,cum3]=ecdf2(x,p) %ECDF2 Empirical cumulative distribution function and % probability density function [CDF,PDF]=ECDF2(X,P). % X is the abscissa vector and P is the data vector. % The result is a row vector. % Copyright Giancarlo Lombardi 1996 k=size(p); l=size(x); if ((k(1)~=1)&(k(2)~=1))|((l(1)~=1)&(l(2)~=1)) error('X and P have to be VECTORS') end if k(2)~=1 p=p.'; end if l(1)~=1 x=x.'; end x=sort(x); pp=length(p); xx=length(x); MAXDIM=100000; BLOCK=ceil(MAXDIM/xx); N=floor(pp/BLOCK); REM=pp-BLOCK*N; cumm=zeros(REM,xx); cumm=p(1:REM,ones(size(x))) < x(ones(size(p(1:REM))),:); cumt=sum(cumm); cumm=zeros(xx,BLOCK); for i=1:N cumm=p(REM+(((i-1)*BLOCK+1):i*BLOCK),ones(size(x))) < x(ones(size(p(REM+(((i-1)*BLOCK+1):i*BLOCK)))),:); cumt=cumt+sum(cumm); end cuma=diff(cumt)./diff(x)/pp; cum2=[cuma 0]; cum=cumt/pp; cum3=(shiftl(cum2,2)+shiftl(cum2,1)+cum2+shiftr(cum2,2)+shiftr(cum2,1))/5;