%function x=surfmin(A)
%
% This function finds local minima on the matrix A.
% For example, if A = [ 1 1 1 1
%                       1 1 0 1
%                       1 1 1 1 ]
%
% then surfmin(A) would return [2 3] since the 2nd
% row and 3rd column of A are the location of a local 
% minimum.

% A.Klein 2/20/98

function x=surfmin(A)

[m,n]=size(A);

x=[];
for i=2:m-1
	for j=2:n-1
		if isempty(find(A(i-1:i+1,j-1:j+1)<A(i,j)))
			x=[x; i j A(i,j)];
		end
	end
end
x=sortrows(x,3);
if ~isempty(x)
	x=x(:,1:2);
end
