function ijdat=zdens1(m,data)

% ZDENS1     Extract bi-variate densities at grid points.
%
%            Example: m=ceil(10*rand(8));
%                     data=genspace(m);
%                     ijdat=zdens1(m,data)
% 
%            Christian C. Beardah 1996

h1=hste(data(:,1),'knorm');
h2=hste(data(:,2),'knorm');

% Delete the final argument of the command below if a plot of the KDE is required.

[x,y,z]=kdfft2(data,'knorm',64,[h1,h2],0);

[r,c]=size(m);
[p,q]=meshgrid(max([1 ceil(min(x))]):min([r floor(max(x))]),max([1 ceil(min(y))]):min([c floor(max(y))]));
X=p(:);
Y=q(:);
ijdat=kdint2([X,Y],x,y,z);
ijdat=[X,Y,ijdat];