function plotgrid(Z)
% function plotgrid(Z)
% Z is a matrix with r rows and c columns, corresponding
% to locations (x,y), indexed (i,j), where x = j, and y = c-i
% the z values might be frequencies or elevations 
% Written by Gerry Middleton, July 1998
zmax = max(max(Z)); % find suitable contour value set
zmin = min(min(Z));
zdif = round((zmax - zmin)/10);
v = [zmin:zdif:zmax];
X = grtodat(Z);     % convert to [x,y,z] format
[r,c] = size(Z);
plot(X(:,1), X(:,2),'o');  % plot points
axis([1 c 1 r]);
axis square;
hold on;
for i = 1:r*c              % label them with z values
   no = num2str(X(i,3));   % comment out these lines if 
   text(X(i,1)+0.1,X(i,2)+0.2,no,'FontSize',4);  % values
end                        % not needed 
Y = flipud(Z);      % flip Z to reverse i indices
contour(Y,v)        % then contour
