% $Id: template $
% Copyright J. V. Mansbridge, CSIRO, Wed Apr 26 11:36:55 EST 2000

m = 8;
n = 6;

z = peaks(max([m n]));
array_2d = round(10*z(1:m, 1:n));
array_2d(3, 2) = NaN;
array_2d(4, 4) = NaN;
array_2d(5, 4) = NaN;
array_2d(1, 3) = NaN;
array_2d(m, 2) = NaN;
array_2d(6, 1) = NaN;
array_2d(6, n) = NaN;

array_2d
[array_2d_new, num_iterations] = fill_gaps_2d(array_2d)
range(array_2d_new - array_2d)

% Some expected answers

% (30 + 1 + 56 + 38 + 9)/5 = 26.8000
% (7 - 11 - 28 - 9 -49 + 4 + 1)/7 = -12.1429
% (-11 - 28 + 6 + 56 + 4 + 1 + 56)/7 = 12

array_2d(1:3, 2:4) = repmat(NaN, 3, 3);
array_2d
[array_2d_new, num_iterations] = fill_gaps_2d(array_2d)
range(array_2d_new - array_2d)

