function xm=mode(x,dx);
%function xm=mode(x,dx);
%            calculates mode (most frequent value) of number
%                dx is digitizing value for reals (default 1)
if nargin==1
       dx=1
end

x=x(find(x~=nan));
n=length(x);
xmin=min(x);
[xs,i]=sort( (x-xmin)/dx+1 );
z(xs)=1:length(xs);
ind=find(z~=0);
z(ind(2:length(ind)))=diff(z(ind));
xm=dx*(findmax(z)-.5)+xmin;

