function [nn]=hist2d(px,py,bx,by)
% hist2d 2 Dimensional histogram
% Usage:: [nn]=hist2d(x,y,binx,biny)
%
% Creates 2D histogram of points x,y in equally spaced bin of size
% diff(bx(1:2)) by diff(by(1:2)), over the range of bx([1 end]) and 
% by([1 end]).


% revision history:
% 05/06/08 Mark D. Shattuck <mds> hist2d.m  

sx=diff(bx(1:2));
sy=diff(by(1:2));

Np=numel(px);
px=(px-bx(1))/sx+1;
py=(py-by(1))/sy+1;
nx=length(bx);
ny=length(by);
nn=zeros(nx,ny);
for np=1:Np
  ii=round(px(np));
  if(ii<1); ii=1;end 
  if(ii>nx); ii=nx;end 
  jj=round(py(np));
  if(jj<1); jj=1;end 
  if(jj>ny); jj=ny;end 
  nn(ii,jj)=nn(ii,jj)+1;
end
