% hist2D % usage: H = hist2D(X,Y,m,n); % find a two dimensional correlation histrogram of two matrix quantities % the returned nxm matrix H satisfies % % H(n-j+1,i) = # of X and Y values satifying % x0 +(i-1)*dx <= X < x0 + i*dx % y0 +(j-1)*dy <= Y < y0 + j*dy % where % x0 = minX, dx = m/(maxX-minX) and y0 = minY, dy = n/(maxY-minY) % the resulting image of H will have the values of X and Y increasing in the standard directions function H = hist2D(X,Y,m,n); X = X(:); Y = Y(:); mX = min(X); MX = max(X); mY = min(Y); MY = max(Y); H = zeros(m,n); X = ceil((m/(MX-mX))*(X-mX)); J = find(X<1); X(J) = 1; J = find(X>m); X(J) = m; Y = ceil((n/(MY-mY))*(Y-mY)); J = find(Y<1); Y(J) = 1; J = find(Y>n); Y(J) = n; for i=1:m for j=1:n H(n-j+1,i)= sum((X ==i)&(Y==j)); end; end;