Mercurial > hg > octave-lyh
diff scripts/general/interpn.m @ 10427:62bb59f927b1
scripts/general/interp2.m, scripts/general/interpn.m: For nearest neighbour interpolation ceil (instead of floor) at the center of the data intervals to be compatible with Matlab. Add test.
author | Soren Hauberg <hauberg@gmail.com> |
---|---|
date | Sat, 20 Mar 2010 14:26:03 -0700 |
parents | 16f53d29049f |
children | 95c3e38098bf |
line wrap: on
line diff
--- a/scripts/general/interpn.m +++ b/scripts/general/interpn.m @@ -149,7 +149,7 @@ endfor idx = cell (1,nd); for i = 1 : nd - idx{i} = yidx{i} + (y{i} - x{i}(yidx{i}) > x{i}(yidx{i} + 1) - y{i}); + idx{i} = yidx{i} + (y{i} - x{i}(yidx{i}) >= x{i}(yidx{i} + 1) - y{i}); endfor vi = v (sub2ind (sz, idx{:})); idx = zeros (prod(yshape),1); @@ -256,3 +256,8 @@ %! [x,y,z] = ndgrid(0:2); %! f = x.^2+y.^2+z.^2; %! assert (interpn(x,y,-z,f,1.5,1.5,-1.5), 7.5) + +%!test % for Matlab-compatible rounding for 'nearest' +%! X = meshgrid (1:4); +%! assert (interpn (X, 2.5, 2.5, 'nearest'), 3); +