% Set any negative elements of matrix A to 0.
% If A is a height field, this "fills" valleys with water
function A = FillWithWater(A);

[m,n] = size(A);
for i = 1:m
for j = 1:n
if A(i,j) < 0
A(i,j) = 0;
end
end
end