Mercurial > hg > octave-nkf
annotate scripts/general/interp2.m @ 10928:a93efb08dc7f
ChangeLog (scipts) typos.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Tue, 31 Aug 2010 07:41:18 -0400 |
parents | e48a45b9a265 |
children | 78a6016875ed |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2000, 2006, 2007, 2008 Kai Habel |
2 ## Copyright (C) 2009 Jaroslav Hajek | |
5837 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
5837 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
5837 | 19 |
20 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
21 ## @deftypefn {Function File} {@var{zi} =} interp2 (@var{x}, @var{y}, @var{z}, @var{xi}, @var{yi}) |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
22 ## @deftypefnx {Function File} {@var{zi} =} interp2 (@var{Z}, @var{xi}, @var{yi}) |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
23 ## @deftypefnx {Function File} {@var{zi} =} interp2 (@var{Z}, @var{n}) |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
24 ## @deftypefnx {Function File} {@var{zi} =} interp2 (@dots{}, @var{method}) |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
25 ## @deftypefnx {Function File} {@var{zi} =} interp2 (@dots{}, @var{method}, @var{extrapval}) |
5837 | 26 ## |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
27 ## Two-dimensional interpolation. @var{x}, @var{y} and @var{z} describe a |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
28 ## surface function. If @var{x} and @var{y} are vectors their length |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
29 ## must correspondent to the size of @var{z}. @var{x} and @var{y} must be |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
30 ## monotonic. If they are matrices they must have the @code{meshgrid} |
5837 | 31 ## format. |
32 ## | |
33 ## @table @code | |
34 ## @item interp2 (@var{x}, @var{y}, @var{Z}, @var{xi}, @var{yi}, @dots{}) | |
35 ## Returns a matrix corresponding to the points described by the | |
8478
5aafd61e4c3c
[docs] @var{XI}, @var{YI}. => @var{xi}, @var{yi}.
Brian Gough <bjg@gnu.org>
parents:
8347
diff
changeset
|
36 ## matrices @var{xi}, @var{yi}. |
5837 | 37 ## |
38 ## If the last argument is a string, the interpolation method can | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
39 ## be specified. The method can be 'linear', 'nearest' or 'cubic'. |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
40 ## If it is omitted 'linear' interpolation is assumed. |
5837 | 41 ## |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
42 ## @item interp2 (@var{z}, @var{xi}, @var{yi}) |
5837 | 43 ## Assumes @code{@var{x} = 1:rows (@var{z})} and @code{@var{y} = |
44 ## 1:columns (@var{z})} | |
45 ## | |
46 ## @item interp2 (@var{z}, @var{n}) | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
47 ## Interleaves the matrix @var{z} n-times. If @var{n} is omitted a value |
5837 | 48 ## of @code{@var{n} = 1} is assumed. |
49 ## @end table | |
50 ## | |
51 ## The variable @var{method} defines the method to use for the | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
52 ## interpolation. It can take one of the following values |
5837 | 53 ## |
54 ## @table @asis | |
55 ## @item 'nearest' | |
6218 | 56 ## Return the nearest neighbor. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
57 ## |
5837 | 58 ## @item 'linear' |
6218 | 59 ## Linear interpolation from nearest neighbors. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
60 ## |
5837 | 61 ## @item 'pchip' |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
10780
diff
changeset
|
62 ## Piece-wise cubic Hermite interpolating polynomial. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
63 ## |
5837 | 64 ## @item 'cubic' |
6218 | 65 ## Cubic interpolation from four nearest neighbors. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
66 ## |
5837 | 67 ## @item 'spline' |
68 ## Cubic spline interpolation--smooth first and second derivatives | |
6702 | 69 ## throughout the curve. |
5837 | 70 ## @end table |
71 ## | |
72 ## If a scalar value @var{extrapval} is defined as the final value, then | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
73 ## values outside the mesh as set to this value. Note that in this case |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
74 ## @var{method} must be defined as well. If @var{extrapval} is not |
6742 | 75 ## defined then NA is assumed. |
5837 | 76 ## |
77 ## @seealso{interp1} | |
78 ## @end deftypefn | |
79 | |
10549 | 80 ## Author: Kai Habel <kai.habel@gmx.de> |
5837 | 81 ## 2005-03-02 Thomas Weber <weber@num.uni-sb.de> |
82 ## * Add test cases | |
83 ## 2005-03-02 Paul Kienzle <pkienzle@users.sf.net> | |
84 ## * Simplify | |
85 ## 2005-04-23 Dmitri A. Sergatskov <dasergatskov@gmail.com> | |
86 ## * Modified demo and test for new gnuplot interface | |
87 ## 2005-09-07 Hoxide <hoxide_dirac@yahoo.com.cn> | |
88 ## * Add bicubic interpolation method | |
5838 | 89 ## * Fix the eat line bug when the last element of XI or YI is |
90 ## negative or zero. | |
5837 | 91 ## 2005-11-26 Pierre Baldensperger <balden@libertysurf.fr> |
92 ## * Rather big modification (XI,YI no longer need to be | |
93 ## "meshgridded") to be consistent with the help message | |
94 ## above and for compatibility. | |
95 | |
96 function ZI = interp2 (varargin) | |
5838 | 97 Z = X = Y = XI = YI = n = []; |
5837 | 98 method = "linear"; |
6742 | 99 extrapval = NA; |
5837 | 100 |
5838 | 101 switch (nargin) |
102 case 1 | |
103 Z = varargin{1}; | |
104 case 2 | |
105 if (ischar (varargin{2})) | |
10549 | 106 [Z, method] = deal (varargin{:}); |
5838 | 107 else |
10549 | 108 [Z, n] = deal (varargin{:}); |
5838 | 109 endif |
110 case 3 | |
111 if (ischar (varargin{3})) | |
10549 | 112 [Z, n, method] = deal (varargin{:}); |
5838 | 113 else |
10549 | 114 [Z, XI, YI] = deal (varargin{:}); |
5838 | 115 endif |
116 case 4 | |
117 if (ischar (varargin{4})) | |
10549 | 118 [Z, XI, YI, method] = deal (varargin{:}); |
5838 | 119 else |
10549 | 120 [Z, n, method, extrapval] = deal (varargin{:}); |
5838 | 121 endif |
122 case 5 | |
123 if (ischar (varargin{4})) | |
10549 | 124 [Z, XI, YI, method, extrapval] = deal (varargin{:}); |
5838 | 125 else |
10549 | 126 [X, Y, Z, XI, YI] = deal (varargin{:}); |
5838 | 127 endif |
128 case 6 | |
10549 | 129 [X, Y, Z, XI, YI, method] = deal (varargin{:}); |
5838 | 130 case 7 |
10549 | 131 [X, Y, Z, XI, YI, method, extrapval] = deal (varargin{:}); |
5838 | 132 otherwise |
133 print_usage (); | |
5837 | 134 endswitch |
135 | |
136 ## Type checking. | |
5838 | 137 if (!ismatrix (Z)) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
138 error ("interp2: expected matrix Z"); |
5837 | 139 endif |
5838 | 140 if (!isempty (n) && !isscalar (n)) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
141 error ("interp2: expected scalar n"); |
5837 | 142 endif |
5838 | 143 if (!ischar (method)) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
144 error ("interp2: expected string 'method'"); |
5837 | 145 endif |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
146 if (ischar (extrapval) || strcmp (extrapval, "extrap")) |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
147 extrapval = []; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
148 elseif (!isscalar (extrapval)) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
149 error ("interp2: expected n extrapval"); |
5837 | 150 endif |
151 | |
5838 | 152 ## Define X, Y, XI, YI if needed |
5837 | 153 [zr, zc] = size (Z); |
5838 | 154 if (isempty (X)) |
155 X = 1:zc; | |
156 Y = 1:zr; | |
5837 | 157 endif |
5838 | 158 if (! isnumeric (X) || ! isnumeric (Y)) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
159 error ("interp2: expected numeric X, Y"); |
5837 | 160 endif |
5838 | 161 if (! isempty (n)) |
162 p = 2^n; | |
163 XI = (p:p*zc)/p; | |
164 YI = (p:p*zr)'/p; | |
5837 | 165 endif |
5838 | 166 if (! isnumeric (XI) || ! isnumeric (YI)) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
167 error ("interp2: expected numeric XI, YI"); |
5837 | 168 endif |
169 | |
6702 | 170 |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
171 if (strcmp (method, "linear") || strcmp (method, "nearest") ... |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
172 || strcmp (method, "pchip")) |
6702 | 173 |
174 ## If X and Y vectors produce a grid from them | |
175 if (isvector (X) && isvector (Y)) | |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
176 X = X(:); Y = Y(:); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
177 elseif (size_equal (X, Y)) |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
178 X = X(1,:)'; Y = Y(:,1); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
179 else |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
180 error ("interp2: X and Y must be matrices of same size"); |
6702 | 181 endif |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
182 if (columns (Z) != length (X) || rows (Z) != length (Y)) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
183 error ("interp2: X and Y size must match Z dimensions"); |
6702 | 184 endif |
185 | |
186 ## If Xi and Yi are vectors of different orientation build a grid | |
187 if ((rows (XI) == 1 && columns (YI) == 1) | |
10549 | 188 || (columns (XI) == 1 && rows (YI) == 1)) |
6702 | 189 [XI, YI] = meshgrid (XI, YI); |
190 elseif (! size_equal (XI, YI)) | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
191 error ("interp2: XI and YI must be matrices of same size"); |
6702 | 192 endif |
5837 | 193 |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
194 ## if XI, YI are vectors, X and Y should share their orientation. |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
195 if (rows (XI) == 1) |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
196 if (rows (X) != 1) |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
197 X = X.'; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
198 endif |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
199 if (rows (Y) != 1) |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
200 Y = Y.'; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
201 endif |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
202 elseif (columns (XI) == 1) |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
203 if (columns (X) != 1) |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
204 X = X.'; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
205 endif |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
206 if (columns (Y) != 1) |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
207 Y = Y.'; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
208 endif |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
209 endif |
6702 | 210 |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
211 xidx = lookup (X, XI, "lr"); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
212 yidx = lookup (Y, YI, "lr"); |
5837 | 213 |
6702 | 214 if (strcmp (method, "linear")) |
215 ## each quad satisfies the equation z(x,y)=a+b*x+c*y+d*xy | |
216 ## | |
217 ## a-b | |
218 ## | | | |
219 ## c-d | |
220 a = Z(1:(zr - 1), 1:(zc - 1)); | |
221 b = Z(1:(zr - 1), 2:zc) - a; | |
222 c = Z(2:zr, 1:(zc - 1)) - a; | |
223 d = Z(2:zr, 2:zc) - a - b - c; | |
5837 | 224 |
6702 | 225 ## scale XI, YI values to a 1-spaced grid |
10326
ade59ae10e80
slight optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
10320
diff
changeset
|
226 Xsc = (XI - X(xidx)) ./ (diff (X)(xidx)); |
ade59ae10e80
slight optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
10320
diff
changeset
|
227 Ysc = (YI - Y(yidx)) ./ (diff (Y)(yidx)); |
6702 | 228 |
10328
2210d3070543
further memory optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
10326
diff
changeset
|
229 ## Get 2D index. |
2210d3070543
further memory optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
10326
diff
changeset
|
230 idx = sub2ind (size (a), yidx, xidx); |
2210d3070543
further memory optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
10326
diff
changeset
|
231 ## We can dispose of the 1D indices at this point to save memory. |
2210d3070543
further memory optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
10326
diff
changeset
|
232 clear xidx yidx |
2210d3070543
further memory optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
10326
diff
changeset
|
233 |
6702 | 234 ## apply plane equation |
235 ZI = a(idx) + b(idx).*Xsc + c(idx).*Ysc + d(idx).*Xsc.*Ysc; | |
5837 | 236 |
6702 | 237 elseif (strcmp (method, "nearest")) |
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:
10328
diff
changeset
|
238 ii = (XI - X(xidx) >= X(xidx + 1) - XI); |
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:
10328
diff
changeset
|
239 jj = (YI - Y(yidx) >= Y(yidx + 1) - YI); |
6702 | 240 idx = sub2ind (size (Z), yidx+jj, xidx+ii); |
241 ZI = Z(idx); | |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
242 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
243 elseif (strcmp (method, "pchip")) |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
244 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
245 if (length (X) < 2 || length (Y) < 2) |
10549 | 246 error ("interp2: pchip2 requires at least 2 points in each dimension") |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
247 endif |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
248 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
249 ## first order derivatives |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
250 DX = __pchip_deriv__ (X, Z, 2); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
251 DY = __pchip_deriv__ (Y, Z, 1); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
252 ## Compute mixed derivatives row-wise and column-wise, use the average. |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
253 DXY = (__pchip_deriv__ (X, DY, 2) + __pchip_deriv__ (Y, DX, 1))/2; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
254 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
255 ## do the bicubic interpolation |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
256 hx = diff (X); hx = hx(xidx); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
257 hy = diff (Y); hy = hy(yidx); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
258 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
259 tx = (XI - X(xidx)) ./ hx; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
260 ty = (YI - Y(yidx)) ./ hy; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
261 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
262 ## construct the cubic hermite base functions in x, y |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
263 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
264 ## formulas: |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
265 ## b{1,1} = ( 2*t.^3 - 3*t.^2 + 1); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
266 ## b{2,1} = h.*( t.^3 - 2*t.^2 + t ); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
267 ## b{1,2} = (-2*t.^3 + 3*t.^2 ); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
268 ## b{2,2} = h.*( t.^3 - t.^2 ); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
269 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
270 ## optimized equivalents of the above: |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
271 t1 = tx.^2; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
272 t2 = tx.*t1 - t1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
273 xb{2,2} = hx.*t2; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
274 t1 = t2 - t1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
275 xb{2,1} = hx.*(t1 + tx); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
276 t2 += t1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
277 xb{1,2} = -t2; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
278 xb{1,1} = t2 + 1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
279 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
280 t1 = ty.^2; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
281 t2 = ty.*t1 - t1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
282 yb{2,2} = hy.*t2; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
283 t1 = t2 - t1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
284 yb{2,1} = hy.*(t1 + ty); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
285 t2 += t1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
286 yb{1,2} = -t2; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
287 yb{1,1} = t2 + 1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
288 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
289 ZI = zeros (size (XI)); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
290 for i = 1:2 |
10549 | 291 for j = 1:2 |
292 zidx = sub2ind (size (Z), yidx+(j-1), xidx+(i-1)); | |
293 ZI += xb{1,i} .* yb{1,j} .* Z(zidx); | |
294 ZI += xb{2,i} .* yb{1,j} .* DX(zidx); | |
295 ZI += xb{1,i} .* yb{2,j} .* DY(zidx); | |
296 ZI += xb{2,i} .* yb{2,j} .* DXY(zidx); | |
297 endfor | |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
298 endfor |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
299 |
6702 | 300 endif |
5837 | 301 |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
302 if (! isempty (extrapval)) |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
303 ## set points outside the table to 'extrapval' |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
304 if (X (1) < X (end)) |
10549 | 305 if (Y (1) < Y (end)) |
306 ZI (XI < X(1,1) | XI > X(end) | YI < Y(1,1) | YI > Y(end)) = ... | |
307 extrapval; | |
308 else | |
309 ZI (XI < X(1) | XI > X(end) | YI < Y(end) | YI > Y(1)) = ... | |
310 extrapval; | |
311 endif | |
6979 | 312 else |
10549 | 313 if (Y (1) < Y (end)) |
314 ZI (XI < X(end) | XI > X(1) | YI < Y(1) | YI > Y(end)) = ... | |
315 extrapval; | |
316 else | |
317 ZI (XI < X(1,end) | XI > X(1) | YI < Y(end) | YI > Y(1)) = ... | |
318 extrapval; | |
319 endif | |
6979 | 320 endif |
321 endif | |
322 | |
6702 | 323 else |
5837 | 324 |
10780
6e7590d003dc
Fix bugs in interp2 (bug #29601)
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10635
diff
changeset
|
325 ## Check dimensions of X and Y |
6702 | 326 if (isvector (X) && isvector (Y)) |
327 X = X(:).'; | |
328 Y = Y(:); | |
329 if (!isequal ([length(X), length(Y)], size(Z))) | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
330 error ("interp2: X and Y size must match Z dimensions"); |
6702 | 331 endif |
332 elseif (!size_equal (X, Y)) | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
333 error ("interp2: X and Y must be matrices of same size"); |
6702 | 334 if (! size_equal (X, Z)) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
335 error ("interp2: X and Y size must match Z dimensions"); |
6702 | 336 endif |
337 endif | |
5837 | 338 |
10780
6e7590d003dc
Fix bugs in interp2 (bug #29601)
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10635
diff
changeset
|
339 ## Check dimensions of XI and YI |
6e7590d003dc
Fix bugs in interp2 (bug #29601)
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10635
diff
changeset
|
340 if (isvector (XI) && isvector (YI)) |
6e7590d003dc
Fix bugs in interp2 (bug #29601)
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10635
diff
changeset
|
341 XI = XI(:).'; |
6e7590d003dc
Fix bugs in interp2 (bug #29601)
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10635
diff
changeset
|
342 YI = YI(:); |
6702 | 343 elseif (! size_equal (XI, YI)) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
344 error ("interp2: XI and YI must be matrices of same size"); |
6702 | 345 endif |
5837 | 346 |
10906
e48a45b9a265
don't use bicubic in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
10821
diff
changeset
|
347 ## FIXME bicubic/__splinen__ don't handle arbitrary XI, YI. |
6702 | 348 if (strcmp (method, "cubic")) |
10906
e48a45b9a265
don't use bicubic in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
10821
diff
changeset
|
349 ## Please remove the dummy zero when bicubic is fixed. |
e48a45b9a265
don't use bicubic in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
10821
diff
changeset
|
350 if (0 && isgriddata (XI) && isgriddata (YI')) |
9755
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
351 ZI = bicubic (X, Y, Z, XI (1, :), YI (:, 1), extrapval); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
352 elseif (isgriddata (X) && isgriddata (Y')) |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
353 ## Allocate output |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
354 ZI = zeros (size (X)); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
355 |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
356 ## Find inliers |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
357 inside = !(XI < X (1) | XI > X (end) | YI < Y (1) | YI > Y (end)); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
358 |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
359 ## Scale XI and YI to match indices of Z |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
360 XI = (columns (Z) - 1) * (XI - X (1)) / (X (end) - X (1)) + 1; |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
361 YI = (rows (Z) - 1) * (YI - Y (1)) / (Y (end) - Y (1)) + 1; |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
362 |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
363 ## Start the real work |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
364 K = floor (XI); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
365 L = floor (YI); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
366 |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
367 ## Coefficients |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
368 AY1 = bc ((YI - L + 1)); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
369 AX1 = bc ((XI - K + 1)); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
370 AY0 = bc ((YI - L + 0)); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
371 AX0 = bc ((XI - K + 0)); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
372 AY_1 = bc ((YI - L - 1)); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
373 AX_1 = bc ((XI - K - 1)); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
374 AY_2 = bc ((YI - L - 2)); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
375 AX_2 = bc ((XI - K - 2)); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
376 |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
377 ## Perform interpolation |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
378 sz = size(Z); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
379 ZI = AY_2 .* AX_2 .* Z (sym_sub2ind (sz, L+2, K+2)) ... |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
380 + AY_2 .* AX_1 .* Z (sym_sub2ind (sz, L+2, K+1)) ... |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
381 + AY_2 .* AX0 .* Z (sym_sub2ind (sz, L+2, K)) ... |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
382 + AY_2 .* AX1 .* Z (sym_sub2ind (sz, L+2, K-1)) ... |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
383 + AY_1 .* AX_2 .* Z (sym_sub2ind (sz, L+1, K+2)) ... |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
384 + AY_1 .* AX_1 .* Z (sym_sub2ind (sz, L+1, K+1)) ... |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
385 + AY_1 .* AX0 .* Z (sym_sub2ind (sz, L+1, K)) ... |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
386 + AY_1 .* AX1 .* Z (sym_sub2ind (sz, L+1, K-1)) ... |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
387 + AY0 .* AX_2 .* Z (sym_sub2ind (sz, L, K+2)) ... |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
388 + AY0 .* AX_1 .* Z (sym_sub2ind (sz, L, K+1)) ... |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
389 + AY0 .* AX0 .* Z (sym_sub2ind (sz, L, K)) ... |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
390 + AY0 .* AX1 .* Z (sym_sub2ind (sz, L, K-1)) ... |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
391 + AY1 .* AX_2 .* Z (sym_sub2ind (sz, L-1, K+2)) ... |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
392 + AY1 .* AX_1 .* Z (sym_sub2ind (sz, L-1, K+1)) ... |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
393 + AY1 .* AX0 .* Z (sym_sub2ind (sz, L-1, K)) ... |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
394 + AY1 .* AX1 .* Z (sym_sub2ind (sz, L-1, K-1)); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
395 ZI (!inside) = extrapval; |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
396 |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
397 else |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
398 error ("interp2: input data must have `meshgrid' format"); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
399 endif |
5837 | 400 |
6702 | 401 elseif (strcmp (method, "spline")) |
9755
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
402 if (isgriddata (XI) && isgriddata (YI')) |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
403 ZI = __splinen__ ({Y(:,1).', X(1,:)}, Z, {YI(:,1), XI(1,:)}, extrapval, |
10549 | 404 "spline"); |
9755
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
405 else |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
406 error ("interp2: input data must have `meshgrid' format"); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
407 endif |
6702 | 408 else |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
409 error ("interp2: interpolation method not recognized"); |
6702 | 410 endif |
5837 | 411 |
6702 | 412 endif |
5837 | 413 endfunction |
414 | |
9755
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
415 function b = isgriddata (X) |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
416 d1 = diff (X, 1, 1); |
10780
6e7590d003dc
Fix bugs in interp2 (bug #29601)
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10635
diff
changeset
|
417 b = all (d1 (:) == 0); |
9755
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
418 endfunction |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
419 |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
420 ## Compute the bicubic interpolation coefficients |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
421 function o = bc(x) |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
422 x = abs(x); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
423 o = zeros(size(x)); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
424 idx1 = (x < 1); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
425 idx2 = !idx1 & (x < 2); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
426 o(idx1) = 1 - 2.*x(idx1).^2 + x(idx1).^3; |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
427 o(idx2) = 4 - 8.*x(idx2) + 5.*x(idx2).^2 - x(idx2).^3; |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
428 endfunction |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
429 |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
430 ## This version of sub2ind behaves as if the data was symmetrically padded |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
431 function ind = sym_sub2ind(sz, Y, X) |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
432 Y (Y < 1) = 1 - Y (Y < 1); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
433 while (any (Y (:) > 2 * sz (1))) |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
434 Y (Y > 2 * sz (1)) = round (Y (Y > 2 * sz (1)) / 2); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
435 endwhile |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
436 Y (Y > sz (1)) = 1 + 2 * sz (1) - Y (Y > sz (1)); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
437 X (X < 1) = 1 - X (X < 1); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
438 while (any (X (:) > 2 * sz (2))) |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
439 X (X > 2 * sz (2)) = round (X (X > 2 * sz (2)) / 2); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
440 endwhile |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
441 X (X > sz (2)) = 1 + 2 * sz (2) - X (X > sz (2)); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
442 ind = sub2ind(sz, Y, X); |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
443 endfunction |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
444 |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
445 |
5837 | 446 %!demo |
447 %! A=[13,-1,12;5,4,3;1,6,2]; | |
448 %! x=[0,1,4]; y=[10,11,12]; | |
449 %! xi=linspace(min(x),max(x),17); | |
450 %! yi=linspace(min(y),max(y),26)'; | |
451 %! mesh(xi,yi,interp2(x,y,A,xi,yi,'linear')); | |
452 %! [x,y] = meshgrid(x,y); | |
453 %! hold on; plot3(x(:),y(:),A(:),"b*"); hold off; | |
454 | |
455 %!demo | |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
456 %! [x,y,A] = peaks(10); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
457 %! x = x(1,:)'; y = y(:,1); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
458 %! xi=linspace(min(x),max(x),41); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
459 %! yi=linspace(min(y),max(y),41)'; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
460 %! mesh(xi,yi,interp2(x,y,A,xi,yi,'linear')); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
461 %! [x,y] = meshgrid(x,y); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
462 %! hold on; plot3(x(:),y(:),A(:),"b*"); hold off; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
463 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
464 %!demo |
5837 | 465 %! A=[13,-1,12;5,4,3;1,6,2]; |
466 %! x=[0,1,4]; y=[10,11,12]; | |
467 %! xi=linspace(min(x),max(x),17); | |
468 %! yi=linspace(min(y),max(y),26)'; | |
469 %! mesh(xi,yi,interp2(x,y,A,xi,yi,'nearest')); | |
470 %! [x,y] = meshgrid(x,y); | |
471 %! hold on; plot3(x(:),y(:),A(:),"b*"); hold off; | |
472 | |
6702 | 473 %!demo |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
474 %! [x,y,A] = peaks(10); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
475 %! x = x(1,:)'; y = y(:,1); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
476 %! xi=linspace(min(x),max(x),41); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
477 %! yi=linspace(min(y),max(y),41)'; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
478 %! mesh(xi,yi,interp2(x,y,A,xi,yi,'nearest')); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
479 %! [x,y] = meshgrid(x,y); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
480 %! hold on; plot3(x(:),y(:),A(:),"b*"); hold off; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
481 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
482 %!demo |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
483 %! A=[13,-1,12;5,4,3;1,6,2]; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
484 %! x=[0,1,2]; y=[10,11,12]; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
485 %! xi=linspace(min(x),max(x),17); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
486 %! yi=linspace(min(y),max(y),26)'; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
487 %! mesh(xi,yi,interp2(x,y,A,xi,yi,'pchip')); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
488 %! [x,y] = meshgrid(x,y); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
489 %! hold on; plot3(x(:),y(:),A(:),"b*"); hold off; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
490 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
491 %!demo |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
492 %! [x,y,A] = peaks(10); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
493 %! x = x(1,:)'; y = y(:,1); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
494 %! xi=linspace(min(x),max(x),41); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
495 %! yi=linspace(min(y),max(y),41)'; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
496 %! mesh(xi,yi,interp2(x,y,A,xi,yi,'pchip')); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
497 %! [x,y] = meshgrid(x,y); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
498 %! hold on; plot3(x(:),y(:),A(:),"b*"); hold off; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
499 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
500 %!demo |
5837 | 501 %! A=[13,-1,12;5,4,3;1,6,2]; |
502 %! x=[0,1,2]; y=[10,11,12]; | |
503 %! xi=linspace(min(x),max(x),17); | |
6702 | 504 %! yi=linspace(min(y),max(y),26)'; |
5837 | 505 %! mesh(xi,yi,interp2(x,y,A,xi,yi,'cubic')); |
506 %! [x,y] = meshgrid(x,y); | |
507 %! hold on; plot3(x(:),y(:),A(:),"b*"); hold off; | |
508 | |
6702 | 509 %!demo |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
510 %! [x,y,A] = peaks(10); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
511 %! x = x(1,:)'; y = y(:,1); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
512 %! xi=linspace(min(x),max(x),41); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
513 %! yi=linspace(min(y),max(y),41)'; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
514 %! mesh(xi,yi,interp2(x,y,A,xi,yi,'cubic')); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
515 %! [x,y] = meshgrid(x,y); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
516 %! hold on; plot3(x(:),y(:),A(:),"b*"); hold off; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
517 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
518 %!demo |
6702 | 519 %! A=[13,-1,12;5,4,3;1,6,2]; |
520 %! x=[0,1,2]; y=[10,11,12]; | |
521 %! xi=linspace(min(x),max(x),17); | |
522 %! yi=linspace(min(y),max(y),26)'; | |
523 %! mesh(xi,yi,interp2(x,y,A,xi,yi,'spline')); | |
524 %! [x,y] = meshgrid(x,y); | |
525 %! hold on; plot3(x(:),y(:),A(:),"b*"); hold off; | |
526 | |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
527 %!demo |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
528 %! [x,y,A] = peaks(10); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
529 %! x = x(1,:)'; y = y(:,1); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
530 %! xi=linspace(min(x),max(x),41); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
531 %! yi=linspace(min(y),max(y),41)'; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
532 %! mesh(xi,yi,interp2(x,y,A,xi,yi,'spline')); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
533 %! [x,y] = meshgrid(x,y); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
534 %! hold on; plot3(x(:),y(:),A(:),"b*"); hold off; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
535 |
5837 | 536 %!test % simple test |
537 %! x = [1,2,3]; | |
538 %! y = [4,5,6,7]; | |
539 %! [X, Y] = meshgrid(x,y); | |
540 %! Orig = X.^2 + Y.^3; | |
541 %! xi = [1.2,2, 1.5]; | |
542 %! yi = [6.2, 4.0, 5.0]'; | |
543 %! | |
544 %! Expected = ... | |
545 %! [243, 245.4, 243.9; | |
546 %! 65.6, 68, 66.5; | |
547 %! 126.6, 129, 127.5]; | |
548 %! Result = interp2(x,y,Orig, xi, yi); | |
549 %! | |
550 %! assert(Result, Expected, 1000*eps); | |
551 | |
552 %!test % 2^n form | |
553 %! x = [1,2,3]; | |
554 %! y = [4,5,6,7]; | |
555 %! [X, Y] = meshgrid(x,y); | |
556 %! Orig = X.^2 + Y.^3; | |
557 %! xi = [1:0.25:3]; yi = [4:0.25:7]'; | |
558 %! Expected = interp2(x,y,Orig, xi, yi); | |
559 %! Result = interp2(Orig,2); | |
560 %! | |
561 %! assert(Result, Expected, 10*eps); | |
562 | |
563 %!test % matrix slice | |
564 %! A = eye(4); | |
565 %! assert(interp2(A,[1:4],[1:4]),[1,1,1,1]); | |
566 | |
567 %!test % non-gridded XI,YI | |
568 %! A = eye(4); | |
569 %! assert(interp2(A,[1,2;3,4],[1,3;2,4]),[1,0;0,1]); | |
570 | |
571 %!test % for values outside of boundaries | |
572 %! x = [1,2,3]; | |
573 %! y = [4,5,6,7]; | |
574 %! [X, Y] = meshgrid(x,y); | |
575 %! Orig = X.^2 + Y.^3; | |
576 %! xi = [0,4]; | |
577 %! yi = [3,8]'; | |
6742 | 578 %! assert(interp2(x,y,Orig, xi, yi),[NA,NA;NA,NA]); |
5837 | 579 %! assert(interp2(x,y,Orig, xi, yi,'linear', 0),[0,0;0,0]); |
580 | |
581 %!test % for values at boundaries | |
582 %! A=[1,2;3,4]; | |
583 %! x=[0,1]; | |
584 %! y=[2,3]'; | |
585 %! assert(interp2(x,y,A,x,y,'linear'), A); | |
586 %! assert(interp2(x,y,A,x,y,'nearest'), A); | |
587 | |
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:
10328
diff
changeset
|
588 %!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:
10328
diff
changeset
|
589 %! 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:
10328
diff
changeset
|
590 %! assert (interp2 (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:
10328
diff
changeset
|
591 |