Mercurial > hg > octave-lyh
annotate scripts/general/interpn.m @ 11188:4cb1522e4d0f
Use function handle as input to cellfun,
rather than quoted function name or anonymous function wrapper.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Wed, 03 Nov 2010 17:20:56 -0700 |
parents | a4f482e66b65 |
children | 1740012184f9 |
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 -*- | |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
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. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10819
diff
changeset
|
47 ## |
6702 | 48 ## @item 'linear' |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
49 ## Linear interpolation from nearest neighbors. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10819
diff
changeset
|
50 ## |
6702 | 51 ## @item 'cubic' |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
52 ## Cubic interpolation from four nearest neighbors (not implemented yet). |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10819
diff
changeset
|
53 ## |
6702 | 54 ## @item 'spline' |
55 ## Cubic spline interpolation--smooth first and second derivatives | |
56 ## throughout the curve. | |
57 ## @end table | |
58 ## | |
59 ## The default method is 'linear'. | |
60 ## | |
8116 | 61 ## 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
|
62 ## beyond the endpoints with that number. If @var{extrapval} is missing, |
8116 | 63 ## assume NA. |
6702 | 64 ## @seealso{interp1, interp2, spline, ndgrid} |
65 ## @end deftypefn | |
66 | |
67 function vi = interpn (varargin) | |
68 | |
69 method = "linear"; | |
6742 | 70 extrapval = NA; |
6702 | 71 nargs = nargin; |
72 | |
73 if (nargin < 1) | |
74 print_usage (); | |
75 endif | |
76 | |
7208 | 77 if (ischar (varargin{end})) |
78 method = varargin{end}; | |
6702 | 79 nargs = nargs - 1; |
7208 | 80 elseif (ischar (varargin{end - 1})) |
81 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
|
82 error ("interpn: extrapal is expected to be a numeric scalar"); |
6702 | 83 endif |
7208 | 84 method = varargin{end - 1}; |
8116 | 85 extrapval = varargin{end}; |
6702 | 86 nargs = nargs - 2; |
87 endif | |
88 | |
89 if (nargs < 3) | |
7208 | 90 v = varargin{1}; |
6702 | 91 m = 1; |
92 if (nargs == 2) | |
7208 | 93 m = varargin{2}; |
6702 | 94 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
|
95 error ("interpn: m is expected to be a integer scalar"); |
6702 | 96 endif |
97 endif | |
98 sz = size (v); | |
99 nd = ndims (v); | |
100 x = cell (1, nd); | |
101 y = cell (1, nd); | |
102 for i = 1 : nd; | |
103 x{i} = 1 : sz(i); | |
104 y{i} = 1 : (1 / (2 ^ m)) : sz(i); | |
105 endfor | |
7208 | 106 elseif (! isvector (varargin{1}) && nargs == (ndims (varargin{1}) + 1)) |
107 v = varargin{1}; | |
6702 | 108 sz = size (v); |
109 nd = ndims (v); | |
110 x = cell (1, nd); | |
111 y = varargin (2 : nargs); | |
112 for i = 1 : nd; | |
113 x{i} = 1 : sz(i); | |
114 endfor | |
115 elseif (rem (nargs, 2) == 1 && nargs == | |
10549 | 116 (2 * ndims (varargin{ceil (nargs / 2)})) + 1) |
6702 | 117 nv = ceil (nargs / 2); |
7208 | 118 v = varargin{nv}; |
6702 | 119 sz = size (v); |
120 nd = ndims (v); | |
121 x = varargin (1 : (nv - 1)); | |
122 y = varargin ((nv + 1) : nargs); | |
123 else | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
124 error ("interpn: wrong number or incorrectly formatted input arguments"); |
6702 | 125 endif |
126 | |
127 if (any (! cellfun (@isvector, x))) | |
128 for i = 2 : nd | |
129 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
|
130 error ("interpn: dimensional mismatch"); |
6702 | 131 endif |
132 idx (1 : nd) = {1}; | |
133 idx (i) = ":"; | |
6721 | 134 x{i} = x{i}(idx{:})(:); |
6702 | 135 endfor |
136 idx (1 : nd) = {1}; | |
137 idx (1) = ":"; | |
6721 | 138 x{1} = x{1}(idx{:})(:); |
6702 | 139 endif |
140 | |
7421 | 141 method = tolower (method); |
6702 | 142 |
10819
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
143 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
|
144 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
|
145 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
|
146 [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
|
147 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
|
148 endif |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
149 |
6702 | 150 if (strcmp (method, "linear")) |
151 vi = __lin_interpn__ (x{:}, v, y{:}); | |
6742 | 152 vi (isna (vi)) = extrapval; |
6702 | 153 elseif (strcmp (method, "nearest")) |
154 yshape = size (y{1}); | |
155 yidx = cell (1, nd); | |
156 for i = 1 : nd | |
157 y{i} = y{i}(:); | |
7671
4fbaba9abec1
implement compiled binary lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7561
diff
changeset
|
158 yidx{i} = lookup (x{i}, y{i}, "lr"); |
6702 | 159 endfor |
160 idx = cell (1,nd); | |
161 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
|
162 idx{i} = yidx{i} + (y{i} - x{i}(yidx{i})(:) >= x{i}(yidx{i} + 1)(:) - y{i}); |
6702 | 163 endfor |
164 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
|
165 idx = zeros (prod (yshape), 1); |
6702 | 166 for i = 1 : nd |
167 idx |= y{i} < min (x{i}(:)) | y{i} > max (x{i}(:)); | |
168 endfor | |
169 vi(idx) = extrapval; | |
170 vi = reshape (vi, yshape); | |
6721 | 171 elseif (strcmp (method, "spline")) |
7423 | 172 if (any (! cellfun (@isvector, y))) |
173 for i = 2 : nd | |
10549 | 174 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
|
175 error ("interpn: dimensional mismatch"); |
10549 | 176 endif |
177 idx (1 : nd) = {1}; | |
178 idx (i) = ":"; | |
179 y{i} = y{i}(idx{:}); | |
7423 | 180 endfor |
181 idx (1 : nd) = {1}; | |
182 idx (1) = ":"; | |
183 y{1} = y{1}(idx{:}); | |
184 endif | |
7421 | 185 |
6702 | 186 vi = __splinen__ (x, v, y, extrapval, "interpn"); |
7421 | 187 |
7423 | 188 if (size_equal (y{:})) |
189 ly = length (y{1}); | |
190 idx = cell (1, ly); | |
191 q = cell (1, nd); | |
192 for i = 1 : ly | |
10549 | 193 q(:) = i; |
194 idx {i} = q; | |
7423 | 195 endfor |
196 vi = vi (cellfun (@(x) sub2ind (size(vi), x{:}), idx)); | |
7424 | 197 vi = reshape (vi, size(y{1})); |
7423 | 198 endif |
6702 | 199 elseif (strcmp (method, "cubic")) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
200 error ("interpn: cubic interpolation not yet implemented"); |
6702 | 201 else |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
202 error ("interpn: unrecognized interpolation method"); |
6702 | 203 endif |
204 | |
205 endfunction | |
206 | |
207 %!demo | |
208 %! A=[13,-1,12;5,4,3;1,6,2]; | |
209 %! x=[0,1,4]; y=[10,11,12]; | |
210 %! 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
|
211 %! yi=linspace(min(y),max(y),26)'; |
6702 | 212 %! mesh(xi,yi,interpn(x,y,A.',xi,yi,"linear").'); |
213 %! [x,y] = meshgrid(x,y); | |
214 %! hold on; plot3(x(:),y(:),A(:),"b*"); hold off; | |
215 | |
216 %!demo | |
217 %! A=[13,-1,12;5,4,3;1,6,2]; | |
218 %! x=[0,1,4]; y=[10,11,12]; | |
219 %! xi=linspace(min(x),max(x),17); | |
220 %! yi=linspace(min(y),max(y),26)'; | |
221 %! mesh(xi,yi,interpn(x,y,A.',xi,yi,"nearest").'); | |
222 %! [x,y] = meshgrid(x,y); | |
223 %! hold on; plot3(x(:),y(:),A(:),"b*"); hold off; | |
224 | |
225 %!#demo | |
226 %! A=[13,-1,12;5,4,3;1,6,2]; | |
227 %! x=[0,1,2]; y=[10,11,12]; | |
228 %! xi=linspace(min(x),max(x),17); | |
229 %! yi=linspace(min(y),max(y),26)'; | |
230 %! mesh(xi,yi,interpn(x,y,A.',xi,yi,"cubic").'); | |
231 %! [x,y] = meshgrid(x,y); | |
232 %! hold on; plot3(x(:),y(:),A(:),"b*"); hold off; | |
233 | |
234 %!demo | |
235 %! A=[13,-1,12;5,4,3;1,6,2]; | |
236 %! x=[0,1,2]; y=[10,11,12]; | |
237 %! xi=linspace(min(x),max(x),17); | |
238 %! yi=linspace(min(y),max(y),26)'; | |
239 %! mesh(xi,yi,interpn(x,y,A.',xi,yi,"spline").'); | |
240 %! [x,y] = meshgrid(x,y); | |
241 %! hold on; plot3(x(:),y(:),A(:),"b*"); hold off; | |
242 | |
6721 | 243 |
244 %!demo | |
245 %! x = y = z = -1:1; | |
246 %! f = @(x,y,z) x.^2 - y - z.^2; | |
247 %! [xx, yy, zz] = meshgrid (x, y, z); | |
248 %! v = f (xx,yy,zz); | |
249 %! xi = yi = zi = -1:0.1:1; | |
250 %! [xxi, yyi, zzi] = ndgrid (xi, yi, zi); | |
251 %! vi = interpn(x, y, z, v, xxi, yyi, zzi, 'spline'); | |
252 %! mesh (yi, zi, squeeze (vi(1,:,:))); | |
253 | |
7421 | 254 |
255 %!test | |
256 %! [x,y,z] = ndgrid(0:2); | |
257 %! f = x+y+z; | |
258 %! assert (interpn(x,y,z,f,[.5 1.5],[.5 1.5],[.5 1.5]), [1.5, 4.5]) | |
259 %! assert (interpn(x,y,z,f,[.51 1.51],[.51 1.51],[.51 1.51],'nearest'), [3, 6]) | |
260 %! assert (interpn(x,y,z,f,[.5 1.5],[.5 1.5],[.5 1.5],'spline'), [1.5, 4.5]) | |
261 %! assert (interpn(x,y,z,f,x,y,z), f) | |
262 %! assert (interpn(x,y,z,f,x,y,z,'nearest'), f) | |
263 %! 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
|
264 |
a938cd7869b2
__lin_interpn__.cc: handle decreasing coordinate values
Alexander Barth
parents:
7424
diff
changeset
|
265 %!test |
10819
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
266 %! [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
|
267 %! 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
|
268 %! 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
|
269 %! 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
|
270 %! 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
|
271 %! 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
|
272 %! [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
|
273 %! 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
|
274 |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
275 %!test |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
276 %! 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
|
277 %! 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
|
278 %! 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
|
279 %! [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
|
280 %! 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
|
281 %! 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
|
282 %! 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
|
283 |
f3c984d45dcb
interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
284 %!test |
7561
a938cd7869b2
__lin_interpn__.cc: handle decreasing coordinate values
Alexander Barth
parents:
7424
diff
changeset
|
285 %! [x,y,z] = ndgrid(0:2); |
a938cd7869b2
__lin_interpn__.cc: handle decreasing coordinate values
Alexander Barth
parents:
7424
diff
changeset
|
286 %! f = x.^2+y.^2+z.^2; |
a938cd7869b2
__lin_interpn__.cc: handle decreasing coordinate values
Alexander Barth
parents:
7424
diff
changeset
|
287 %! 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
|
288 |
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 %!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
|
290 %! 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
|
291 %! 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
|
292 |