diff --git a/hist2.m b/hist2.m index e0ccddd3f9b79c5d7a7912c0082f1a4ecaadbb39..b9b0885ef30e241068f7a01271e415046affae21 100644 --- a/hist2.m +++ b/hist2.m @@ -25,7 +25,7 @@ function varargout=hist2(varargin) % % See also HIST, HISTN, BAR3, MI. -% Copyright (c) 2002-2003 +% Copyright (c) 2002-2007 % Andre Sitz, Norbert Marwan, Potsdam University, Germany % http://www.agnld.uni-potsdam.de % @@ -33,6 +33,9 @@ function varargout=hist2(varargin) % $Revision$ % % $Log$ +% Revision 1.10 2006/07/04 14:05:08 marwan +% lag = zero allowed +% % Revision 1.9 2004/11/10 07:05:37 marwan % initial import % @@ -82,15 +85,21 @@ if size(x,1)<size(x,2), x=x';end if size(y,1)<size(y,2), y=y';end x=x(:,1); y=y(:,1); %x=x(:); y=y(:); -x1=(x-min(x))/max(x-min(x))-eps; -y1=(y-min(y))/max(y-min(y))-eps; + +% normalise the value range to [0 1) +x1 = (x - min(x)) / max(x - min(x)) - eps; +y1 = (y - min(y)) / max(y - min(y)) - eps; + if length(x)<=lag, lag=length(x)-1; warning(['Lag is too large. Using ',num2str(lag),' instead.']), end -temp=fix(x1(1:(end-lag))*nbin)+(fix(y1((lag+1):end)*nbin))*nbin; +% this is the main trick: put the first data to values [1:1:nbin] and the second data to [nbin:nbin:nbin^2] +temp = fix(x1(1:(end-lag)) * nbin) + (fix(y1((lag+1):end) * nbin)) * nbin; +% call Matlab histc function (faster than hist) p=histc(temp,0:(nbin^2-1))'; p2=reshape(p,nbin,nbin)/length(x); +% create the correct bin denominator minx = min(min(x)); maxx = max(max(x)); if minx == maxx, minx = minx - floor(nbin/2) - 0.5; maxx = maxx + ceil(nbin/2) - 0.5; end miny = min(min(y)); maxy = max(max(y));