Mercurial > hg > octave-nkf
annotate scripts/general/interpn.m @ 10819:f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Mon, 26 Jul 2010 07:34:37 -0400 |
parents | be55736a0783 |
children | 693e22af08ae |
rev | line source |
---|---|
9245 | 1 ## Copyright (C) 2007, 2008, 2009 David Bateman |
6702 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
6702 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
6702 | 18 |
19 ## -*- texinfo -*- | |
10819
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
20 ## @deftypefn {Function File} {@var{vi} =} interpn (@var{x1}, @var{x2}, @dots{}, @var{v}, @var{y1}, @var{y2}, @dots{}) |
6702 | 21 ## @deftypefnx {Function File} {@var{vi} =} interpn (@var{v}, @var{y1}, @var{y2}, @dots{}) |
22 ## @deftypefnx {Function File} {@var{vi} =} interpn (@var{v}, @var{m}) | |
23 ## @deftypefnx {Function File} {@var{vi} =} interpn (@var{v}) | |
24 ## @deftypefnx {Function File} {@var{vi} =} interpn (@dots{}, @var{method}) | |
25 ## @deftypefnx {Function File} {@var{vi} =} interpn (@dots{}, @var{method}, @var{extrapval}) | |
26 ## | |
27 ## Perform @var{n}-dimensional interpolation, where @var{n} is at least two. | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8116
diff
changeset
|
28 ## Each element of the @var{n}-dimensional array @var{v} represents a value |
6702 | 29 ## at a location given by the parameters @var{x1}, @var{x2}, @dots{}, @var{xn}. |
30 ## The parameters @var{x1}, @var{x2}, @dots{}, @var{xn} are either | |
31 ## @var{n}-dimensional arrays of the same size as the array @var{v} in | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9070
diff
changeset
|
32 ## the 'ndgrid' format or vectors. The parameters @var{y1}, etc. respect a |
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9070
diff
changeset
|
33 ## similar format to @var{x1}, etc., and they represent the points at which |
6702 | 34 ## the array @var{vi} is interpolated. |
35 ## | |
7001 | 36 ## If @var{x1}, @dots{}, @var{xn} are omitted, they are assumed to be |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
37 ## @code{x1 = 1 : size (@var{v}, 1)}, etc. If @var{m} is specified, then |
7001 | 38 ## the interpolation adds a point half way between each of the interpolation |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
39 ## points. This process is performed @var{m} times. If only @var{v} is |
6702 | 40 ## specified, then @var{m} is assumed to be @code{1}. |
41 ## | |
42 ## Method is one of: | |
43 ## | |
44 ## @table @asis | |
45 ## @item 'nearest' | |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
46 ## Return the nearest neighbor. |
6702 | 47 ## @item 'linear' |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
48 ## Linear interpolation from nearest neighbors. |
6702 | 49 ## @item 'cubic' |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
50 ## Cubic interpolation from four nearest neighbors (not implemented yet). |
6702 | 51 ## @item 'spline' |
52 ## Cubic spline interpolation--smooth first and second derivatives | |
53 ## throughout the curve. | |
54 ## @end table | |
55 ## | |
56 ## The default method is 'linear'. | |
57 ## | |
8116 | 58 ## If @var{extrapval} is the scalar value, use it to replace the values |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
59 ## beyond the endpoints with that number. If @var{extrapval} is missing, |
8116 | 60 ## assume NA. |
6702 | 61 ## @seealso{interp1, interp2, spline, ndgrid} |
62 ## @end deftypefn | |
63 | |
64 function vi = interpn (varargin) | |
65 | |
66 method = "linear"; | |
6742 | 67 extrapval = NA; |
6702 | 68 nargs = nargin; |
69 | |
70 if (nargin < 1) | |
71 print_usage (); | |
72 endif | |
73 | |
7208 | 74 if (ischar (varargin{end})) |
75 method = varargin{end}; | |
6702 | 76 nargs = nargs - 1; |
7208 | 77 elseif (ischar (varargin{end - 1})) |
78 if (! isnumeric (varargin{end}) || ! isscalar (varargin{end})) | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
79 error ("interpn: extrapal is expected to be a numeric scalar"); |
6702 | 80 endif |
7208 | 81 method = varargin{end - 1}; |
8116 | 82 extrapval = varargin{end}; |
6702 | 83 nargs = nargs - 2; |
84 endif | |
85 | |
86 if (nargs < 3) | |
7208 | 87 v = varargin{1}; |
6702 | 88 m = 1; |
89 if (nargs == 2) | |
7208 | 90 m = varargin{2}; |
6702 | 91 if (! isnumeric (m) || ! isscalar (m) || floor (m) != m) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
92 error ("interpn: m is expected to be a integer scalar"); |
6702 | 93 endif |
94 endif | |
95 sz = size (v); | |
96 nd = ndims (v); | |
97 x = cell (1, nd); | |
98 y = cell (1, nd); | |
99 for i = 1 : nd; | |
100 x{i} = 1 : sz(i); | |
101 y{i} = 1 : (1 / (2 ^ m)) : sz(i); | |
102 endfor | |
7208 | 103 elseif (! isvector (varargin{1}) && nargs == (ndims (varargin{1}) + 1)) |
104 v = varargin{1}; | |
6702 | 105 sz = size (v); |
106 nd = ndims (v); | |
107 x = cell (1, nd); | |
108 y = varargin (2 : nargs); | |
109 for i = 1 : nd; | |
110 x{i} = 1 : sz(i); | |
111 endfor | |
112 elseif (rem (nargs, 2) == 1 && nargs == | |
10549 | 113 (2 * ndims (varargin{ceil (nargs / 2)})) + 1) |
6702 | 114 nv = ceil (nargs / 2); |
7208 | 115 v = varargin{nv}; |
6702 | 116 sz = size (v); |
117 nd = ndims (v); | |
118 x = varargin (1 : (nv - 1)); | |
119 y = varargin ((nv + 1) : nargs); | |
120 else | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
121 error ("interpn: wrong number or incorrectly formatted input arguments"); |
6702 | 122 endif |
123 | |
124 if (any (! cellfun (@isvector, x))) | |
125 for i = 2 : nd | |
126 if (! size_equal (x{1}, x{i}) || ! size_equal (x{i}, v)) | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
127 error ("interpn: dimensional mismatch"); |
6702 | 128 endif |
129 idx (1 : nd) = {1}; | |
130 idx (i) = ":"; | |
6721 | 131 x{i} = x{i}(idx{:})(:); |
6702 | 132 endfor |
133 idx (1 : nd) = {1}; | |
134 idx (1) = ":"; | |
6721 | 135 x{1} = x{1}(idx{:})(:); |
6702 | 136 endif |
137 | |
7421 | 138 method = tolower (method); |
6702 | 139 |
10819
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
140 all_vectors = all (cellfun (@isvector, y)); |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
141 different_lengths = numel (unique (cellfun (@numel, y))) > 1; |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
142 if (all_vectors && different_lengths) |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
143 [foobar(1:numel(y)).y] = ndgrid (y{:}); |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
144 y = {foobar.y}; |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
145 endif |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
146 |
6702 | 147 if (strcmp (method, "linear")) |
148 vi = __lin_interpn__ (x{:}, v, y{:}); | |
6742 | 149 vi (isna (vi)) = extrapval; |
6702 | 150 elseif (strcmp (method, "nearest")) |
151 yshape = size (y{1}); | |
152 yidx = cell (1, nd); | |
153 for i = 1 : nd | |
154 y{i} = y{i}(:); | |
7671
4fbaba9abec1
implement compiled binary lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7561
diff
changeset
|
155 yidx{i} = lookup (x{i}, y{i}, "lr"); |
6702 | 156 endfor |
157 idx = cell (1,nd); | |
158 for i = 1 : nd | |
10819
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
159 idx{i} = yidx{i} + (y{i} - x{i}(yidx{i})(:) >= x{i}(yidx{i} + 1)(:) - y{i}); |
6702 | 160 endfor |
161 vi = v (sub2ind (sz, idx{:})); | |
10819
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
162 idx = zeros (prod (yshape), 1); |
6702 | 163 for i = 1 : nd |
164 idx |= y{i} < min (x{i}(:)) | y{i} > max (x{i}(:)); | |
165 endfor | |
166 vi(idx) = extrapval; | |
167 vi = reshape (vi, yshape); | |
6721 | 168 elseif (strcmp (method, "spline")) |
7423 | 169 if (any (! cellfun (@isvector, y))) |
170 for i = 2 : nd | |
10549 | 171 if (! size_equal (y{1}, y{i})) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
172 error ("interpn: dimensional mismatch"); |
10549 | 173 endif |
174 idx (1 : nd) = {1}; | |
175 idx (i) = ":"; | |
176 y{i} = y{i}(idx{:}); | |
7423 | 177 endfor |
178 idx (1 : nd) = {1}; | |
179 idx (1) = ":"; | |
180 y{1} = y{1}(idx{:}); | |
181 endif | |
7421 | 182 |
6702 | 183 vi = __splinen__ (x, v, y, extrapval, "interpn"); |
7421 | 184 |
7423 | 185 if (size_equal (y{:})) |
186 ly = length (y{1}); | |
187 idx = cell (1, ly); | |
188 q = cell (1, nd); | |
189 for i = 1 : ly | |
10549 | 190 q(:) = i; |
191 idx {i} = q; | |
7423 | 192 endfor |
193 vi = vi (cellfun (@(x) sub2ind (size(vi), x{:}), idx)); | |
7424 | 194 vi = reshape (vi, size(y{1})); |
7423 | 195 endif |
6702 | 196 elseif (strcmp (method, "cubic")) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
197 error ("interpn: cubic interpolation not yet implemented"); |
6702 | 198 else |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
199 error ("interpn: unrecognized interpolation method"); |
6702 | 200 endif |
201 | |
202 endfunction | |
203 | |
204 %!demo | |
205 %! A=[13,-1,12;5,4,3;1,6,2]; | |
206 %! x=[0,1,4]; y=[10,11,12]; | |
207 %! xi=linspace(min(x),max(x),17); | |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
208 %! yi=linspace(min(y),max(y),26)'; |
6702 | 209 %! mesh(xi,yi,interpn(x,y,A.',xi,yi,"linear").'); |
210 %! [x,y] = meshgrid(x,y); | |
211 %! hold on; plot3(x(:),y(:),A(:),"b*"); hold off; | |
212 | |
213 %!demo | |
214 %! A=[13,-1,12;5,4,3;1,6,2]; | |
215 %! x=[0,1,4]; y=[10,11,12]; | |
216 %! xi=linspace(min(x),max(x),17); | |
217 %! yi=linspace(min(y),max(y),26)'; | |
218 %! mesh(xi,yi,interpn(x,y,A.',xi,yi,"nearest").'); | |
219 %! [x,y] = meshgrid(x,y); | |
220 %! hold on; plot3(x(:),y(:),A(:),"b*"); hold off; | |
221 | |
222 %!#demo | |
223 %! A=[13,-1,12;5,4,3;1,6,2]; | |
224 %! x=[0,1,2]; y=[10,11,12]; | |
225 %! xi=linspace(min(x),max(x),17); | |
226 %! yi=linspace(min(y),max(y),26)'; | |
227 %! mesh(xi,yi,interpn(x,y,A.',xi,yi,"cubic").'); | |
228 %! [x,y] = meshgrid(x,y); | |
229 %! hold on; plot3(x(:),y(:),A(:),"b*"); hold off; | |
230 | |
231 %!demo | |
232 %! A=[13,-1,12;5,4,3;1,6,2]; | |
233 %! x=[0,1,2]; y=[10,11,12]; | |
234 %! xi=linspace(min(x),max(x),17); | |
235 %! yi=linspace(min(y),max(y),26)'; | |
236 %! mesh(xi,yi,interpn(x,y,A.',xi,yi,"spline").'); | |
237 %! [x,y] = meshgrid(x,y); | |
238 %! hold on; plot3(x(:),y(:),A(:),"b*"); hold off; | |
239 | |
6721 | 240 |
241 %!demo | |
242 %! x = y = z = -1:1; | |
243 %! f = @(x,y,z) x.^2 - y - z.^2; | |
244 %! [xx, yy, zz] = meshgrid (x, y, z); | |
245 %! v = f (xx,yy,zz); | |
246 %! xi = yi = zi = -1:0.1:1; | |
247 %! [xxi, yyi, zzi] = ndgrid (xi, yi, zi); | |
248 %! vi = interpn(x, y, z, v, xxi, yyi, zzi, 'spline'); | |
249 %! mesh (yi, zi, squeeze (vi(1,:,:))); | |
250 | |
7421 | 251 |
252 %!test | |
253 %! [x,y,z] = ndgrid(0:2); | |
254 %! f = x+y+z; | |
255 %! assert (interpn(x,y,z,f,[.5 1.5],[.5 1.5],[.5 1.5]), [1.5, 4.5]) | |
256 %! assert (interpn(x,y,z,f,[.51 1.51],[.51 1.51],[.51 1.51],'nearest'), [3, 6]) | |
257 %! assert (interpn(x,y,z,f,[.5 1.5],[.5 1.5],[.5 1.5],'spline'), [1.5, 4.5]) | |
258 %! assert (interpn(x,y,z,f,x,y,z), f) | |
259 %! assert (interpn(x,y,z,f,x,y,z,'nearest'), f) | |
260 %! assert (interpn(x,y,z,f,x,y,z,'spline'), f) | |
7561
a938cd7869b2
__lin_interpn__.cc: handle decreasing coordinate values
Alexander Barth
parents:
7424
diff
changeset
|
261 |
a938cd7869b2
__lin_interpn__.cc: handle decreasing coordinate values
Alexander Barth
parents:
7424
diff
changeset
|
262 %!test |
10819
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
263 %! [x, y, z] = ndgrid (0:2, 1:4, 2:6); |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
264 %! f = x + y + z; |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
265 %! xi = [0.5 1.0 1.5]; |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
266 %! yi = [1.5 2.0 2.5 3.5]; |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
267 %! zi = [2.5 3.5 4.0 5.0 5.5]; |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
268 %! fi = interpn (x, y, z, f, xi, yi, zi); |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
269 %! [xi, yi, zi] = ndgrid (xi, yi, zi); |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
270 %! assert (fi, xi + yi + zi) |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
271 |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
272 %!test |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
273 %! xi = 0:2; |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
274 %! yi = 1:4; |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
275 %! zi = 2:6; |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
276 %! [x, y, z] = ndgrid (xi, yi, zi); |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
277 %! f = x + y + z; |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
278 %! fi = interpn (x, y, z, f, xi, yi, zi, "nearest"); |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
279 %! assert (fi, x + y + z) |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
280 |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
281 %!test |
7561
a938cd7869b2
__lin_interpn__.cc: handle decreasing coordinate values
Alexander Barth
parents:
7424
diff
changeset
|
282 %! [x,y,z] = ndgrid(0:2); |
a938cd7869b2
__lin_interpn__.cc: handle decreasing coordinate values
Alexander Barth
parents:
7424
diff
changeset
|
283 %! f = x.^2+y.^2+z.^2; |
a938cd7869b2
__lin_interpn__.cc: handle decreasing coordinate values
Alexander Barth
parents:
7424
diff
changeset
|
284 %! assert (interpn(x,y,-z,f,1.5,1.5,-1.5), 7.5) |
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.
Soren Hauberg <hauberg@gmail.com>
parents:
9245
diff
changeset
|
285 |
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.
Soren Hauberg <hauberg@gmail.com>
parents:
9245
diff
changeset
|
286 %!test % for Matlab-compatible rounding for 'nearest' |
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.
Soren Hauberg <hauberg@gmail.com>
parents:
9245
diff
changeset
|
287 %! X = meshgrid (1:4); |
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.
Soren Hauberg <hauberg@gmail.com>
parents:
9245
diff
changeset
|
288 %! assert (interpn (X, 2.5, 2.5, 'nearest'), 3); |
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.
Soren Hauberg <hauberg@gmail.com>
parents:
9245
diff
changeset
|
289 |