function hist2D ( X, NBins, Smooth, N ) % % function [ H ] = hist2D ( X, NBins, Smooth ) % % Computes and display a 2D histogram. The axes will be set such that % all data points are visible. % % Input % % X 2 x N Matrix of data points. Points are stored % as columns % % NBins 2 x 1 Number of bins in each dimension % % Smooth scalar Size of smoothing kernel used as Parzen window % % N scalar Number of contour lines to be drawn. % % % (c) in 1998 by California Institute of Technology % % Markus Weber % % % $Log: hist2D.m,v $ % Revision 1.1 1999/05/05 21:14:40 mweber % Minor changes. % % Revision 1.2 1999/05/05 21:07:01 mweber % Complete overhaul. % % Revision 1.1.1.1 1999/05/05 17:50:09 mweber % Initial import % H = zeros(NBins(2), NBins(1)); xMin = min(X(1, :)); xMax = max(X(1, :)); yMin = min(X(2, :)); yMax = max(X(2, :)); dX = (xMax - xMin) / (NBins(1) - 1); dY = (yMax - yMin) / (NBins(2) - 1); BX = 1 + floor((X(1, :) - xMin) / dX + 0.5); BY = 1 + floor((X(2, :) - yMin) / dY + 0.5); for i = 1 : size(X, 2), H(BY(i), BX(i)) = H(BY(i), BX(i)) + 1; end H = gaussN(H, Smooth); [XX YY] = meshgrid(xMin : dX : xMax, yMin : dY : yMax); contour(XX, YY, H, N); axis('image');