Mercurial > octave-nkf
annotate scripts/general/interp2.m @ 14237:11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Add clf() to all demos using plot features to get reproducibility.
Use 64 as input to all colormaps (jet (64)) to get reproducibility.
* bicubic.m, cell2mat.m, celldisp.m, cplxpair.m, interp1.m, interp2.m,
interpft.m, interpn.m, profile.m, profshow.m, convhull.m, delaunay.m,
griddata.m, inpolygon.m, voronoi.m, autumn.m, bone.m, contrast.m, cool.m,
copper.m, flag.m, gmap40.m, gray.m, hot.m, hsv.m, image.m, imshow.m, jet.m,
ocean.m, pink.m, prism.m, rainbow.m, spring.m, summer.m, white.m, winter.m,
condest.m, onenormest.m, axis.m, clabel.m, colorbar.m, comet.m, comet3.m,
compass.m, contour.m, contour3.m, contourf.m, cylinder.m, daspect.m,
ellipsoid.m, errorbar.m, ezcontour.m, ezcontourf.m, ezmesh.m, ezmeshc.m,
ezplot.m, ezplot3.m, ezpolar.m, ezsurf.m, ezsurfc.m, feather.m, fill.m,
fplot.m, grid.m, hold.m, isosurface.m, legend.m, loglog.m, loglogerr.m,
pareto.m, patch.m, pbaspect.m, pcolor.m, pie.m, pie3.m, plot3.m, plotmatrix.m,
plotyy.m, polar.m, quiver.m, quiver3.m, rectangle.m, refreshdata.m, ribbon.m,
rose.m, scatter.m, scatter3.m, semilogx.m, semilogxerr.m, semilogy.m,
semilogyerr.m, shading.m, slice.m, sombrero.m, stairs.m, stem.m, stem3.m,
subplot.m, surf.m, surfc.m, surfl.m, surfnorm.m, text.m, title.m, trimesh.m,
triplot.m, trisurf.m, uigetdir.m, uigetfile.m, uimenu.m, uiputfile.m,
waitbar.m, xlim.m, ylim.m, zlim.m, mkpp.m, pchip.m, polyaffine.m, spline.m,
bicgstab.m, cgs.m, gplot.m, pcg.m, pcr.m, treeplot.m, strtok.m, demo.m,
example.m, rundemos.m, speed.m, test.m, calendar.m, datestr.m, datetick.m,
weekday.m: Revamp %!demos to use Octave coding conventions on spacing, etc.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Fri, 20 Jan 2012 12:59:53 -0800 |
parents | 72c96de7a403 |
children | c4fa5e0b6193 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13149
diff
changeset
|
1 ## Copyright (C) 2000-2012 Kai Habel |
8920 | 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 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
30 ## monotonic. If they are matrices they must have the @code{meshgrid} |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
31 ## format. |
5837 | 32 ## |
33 ## @table @code | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
34 ## @item interp2 (@var{x}, @var{y}, @var{Z}, @var{xi}, @var{yi}, @dots{}) |
5837 | 35 ## Returns a matrix corresponding to the points described by the |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
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}) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
43 ## Assumes @code{@var{x} = 1:rows (@var{z})} and @code{@var{y} = |
5837 | 44 ## 1:columns (@var{z})} |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
45 ## |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
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 | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
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' |
11536
702dbd0c53f5
Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
62 ## Piecewise 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' |
12175
2090995ca588
Correct en-dash,em-dash instances in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
11589
diff
changeset
|
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 | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
73 ## values outside the mesh as set to this value. Note that in this case |
9051
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 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
75 ## defined then NA is assumed. |
5837 | 76 ## |
77 ## @seealso{interp1} | |
78 ## @end deftypefn | |
79 | |
10549 | 80 ## Author: Kai Habel <kai.habel@gmx.de> |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
81 ## 2005-03-02 Thomas Weber <weber@num.uni-sb.de> |
5837 | 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}; | |
13149
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
104 n = 1; |
5838 | 105 case 2 |
106 if (ischar (varargin{2})) | |
10549 | 107 [Z, method] = deal (varargin{:}); |
13149
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
108 n = 1; |
5838 | 109 else |
10549 | 110 [Z, n] = deal (varargin{:}); |
5838 | 111 endif |
112 case 3 | |
113 if (ischar (varargin{3})) | |
10549 | 114 [Z, n, method] = deal (varargin{:}); |
5838 | 115 else |
10549 | 116 [Z, XI, YI] = deal (varargin{:}); |
5838 | 117 endif |
118 case 4 | |
119 if (ischar (varargin{4})) | |
10549 | 120 [Z, XI, YI, method] = deal (varargin{:}); |
5838 | 121 else |
10549 | 122 [Z, n, method, extrapval] = deal (varargin{:}); |
5838 | 123 endif |
124 case 5 | |
125 if (ischar (varargin{4})) | |
10549 | 126 [Z, XI, YI, method, extrapval] = deal (varargin{:}); |
5838 | 127 else |
10549 | 128 [X, Y, Z, XI, YI] = deal (varargin{:}); |
5838 | 129 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
130 case 6 |
10549 | 131 [X, Y, Z, XI, YI, method] = deal (varargin{:}); |
5838 | 132 case 7 |
10549 | 133 [X, Y, Z, XI, YI, method, extrapval] = deal (varargin{:}); |
5838 | 134 otherwise |
135 print_usage (); | |
5837 | 136 endswitch |
137 | |
138 ## Type checking. | |
5838 | 139 if (!ismatrix (Z)) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
140 error ("interp2: Z must be a matrix"); |
5837 | 141 endif |
5838 | 142 if (!isempty (n) && !isscalar (n)) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
143 error ("interp2: N must be a scalar"); |
5837 | 144 endif |
5838 | 145 if (!ischar (method)) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
146 error ("interp2: METHOD must be a string"); |
5837 | 147 endif |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
148 if (ischar (extrapval) || strcmp (extrapval, "extrap")) |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
149 extrapval = []; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
150 elseif (!isscalar (extrapval)) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11108
diff
changeset
|
151 error ("interp2: EXTRAPVAL must be a scalar"); |
5837 | 152 endif |
153 | |
5838 | 154 ## Define X, Y, XI, YI if needed |
5837 | 155 [zr, zc] = size (Z); |
5838 | 156 if (isempty (X)) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
157 X = 1:zc; |
5838 | 158 Y = 1:zr; |
5837 | 159 endif |
5838 | 160 if (! isnumeric (X) || ! isnumeric (Y)) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
161 error ("interp2: X, Y must be numeric matrices"); |
5837 | 162 endif |
5838 | 163 if (! isempty (n)) |
13149
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
164 ## Calculate the interleaved input vectors. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
165 p = 2^n; |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
166 XI = (p:p*zc)/p; |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
167 YI = (p:p*zr)'/p; |
5837 | 168 endif |
5838 | 169 if (! isnumeric (XI) || ! isnumeric (YI)) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
170 error ("interp2: XI, YI must be numeric"); |
5837 | 171 endif |
172 | |
6702 | 173 |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
174 if (strcmp (method, "linear") || strcmp (method, "nearest") ... |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
175 || strcmp (method, "pchip")) |
6702 | 176 |
177 ## If X and Y vectors produce a grid from them | |
178 if (isvector (X) && isvector (Y)) | |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
179 X = X(:); Y = Y(:); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
180 elseif (size_equal (X, Y)) |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
181 X = X(1,:)'; Y = Y(:,1); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
182 else |
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 must be matrices of same size"); |
6702 | 184 endif |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
185 if (columns (Z) != length (X) || rows (Z) != length (Y)) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11108
diff
changeset
|
186 error ("interp2: X and Y size must match the dimensions of Z"); |
6702 | 187 endif |
188 | |
189 ## If Xi and Yi are vectors of different orientation build a grid | |
190 if ((rows (XI) == 1 && columns (YI) == 1) | |
10549 | 191 || (columns (XI) == 1 && rows (YI) == 1)) |
6702 | 192 [XI, YI] = meshgrid (XI, YI); |
193 elseif (! size_equal (XI, YI)) | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11108
diff
changeset
|
194 error ("interp2: XI and YI must be matrices of equal size"); |
6702 | 195 endif |
5837 | 196 |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
197 ## 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
|
198 if (rows (XI) == 1) |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
199 if (rows (X) != 1) |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
200 X = X.'; |
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 if (rows (Y) != 1) |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
203 Y = Y.'; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
204 endif |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
205 elseif (columns (XI) == 1) |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
206 if (columns (X) != 1) |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
207 X = X.'; |
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 if (columns (Y) != 1) |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
210 Y = Y.'; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
211 endif |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
212 endif |
6702 | 213 |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
214 xidx = lookup (X, XI, "lr"); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
215 yidx = lookup (Y, YI, "lr"); |
5837 | 216 |
6702 | 217 if (strcmp (method, "linear")) |
218 ## each quad satisfies the equation z(x,y)=a+b*x+c*y+d*xy | |
219 ## | |
220 ## a-b | |
221 ## | | | |
222 ## c-d | |
223 a = Z(1:(zr - 1), 1:(zc - 1)); | |
224 b = Z(1:(zr - 1), 2:zc) - a; | |
225 c = Z(2:zr, 1:(zc - 1)) - a; | |
226 d = Z(2:zr, 2:zc) - a - b - c; | |
5837 | 227 |
6702 | 228 ## scale XI, YI values to a 1-spaced grid |
10326
ade59ae10e80
slight optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
10320
diff
changeset
|
229 Xsc = (XI - X(xidx)) ./ (diff (X)(xidx)); |
ade59ae10e80
slight optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
10320
diff
changeset
|
230 Ysc = (YI - Y(yidx)) ./ (diff (Y)(yidx)); |
6702 | 231 |
10328
2210d3070543
further memory optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
10326
diff
changeset
|
232 ## Get 2D index. |
2210d3070543
further memory optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
10326
diff
changeset
|
233 idx = sub2ind (size (a), yidx, xidx); |
2210d3070543
further memory optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
10326
diff
changeset
|
234 ## We can dispose of the 1D indices at this point to save memory. |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
235 clear xidx yidx; |
10328
2210d3070543
further memory optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
10326
diff
changeset
|
236 |
6702 | 237 ## apply plane equation |
238 ZI = a(idx) + b(idx).*Xsc + c(idx).*Ysc + d(idx).*Xsc.*Ysc; | |
5837 | 239 |
6702 | 240 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
|
241 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
|
242 jj = (YI - Y(yidx) >= Y(yidx + 1) - YI); |
6702 | 243 idx = sub2ind (size (Z), yidx+jj, xidx+ii); |
244 ZI = Z(idx); | |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
245 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
246 elseif (strcmp (method, "pchip")) |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
247 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
248 if (length (X) < 2 || length (Y) < 2) |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
249 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
|
250 endif |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
251 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
252 ## first order derivatives |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
253 DX = __pchip_deriv__ (X, Z, 2); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
254 DY = __pchip_deriv__ (Y, Z, 1); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
255 ## 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
|
256 DXY = (__pchip_deriv__ (X, DY, 2) + __pchip_deriv__ (Y, DX, 1))/2; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
257 |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
258 ## do the bicubic interpolation |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
259 hx = diff (X); hx = hx(xidx); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
260 hy = diff (Y); hy = hy(yidx); |
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 tx = (XI - X(xidx)) ./ hx; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
263 ty = (YI - Y(yidx)) ./ hy; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
264 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
265 ## construct the cubic hermite base functions in x, y |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
266 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
267 ## formulas: |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
268 ## 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
|
269 ## 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
|
270 ## b{1,2} = (-2*t.^3 + 3*t.^2 ); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
271 ## b{2,2} = h.*( t.^3 - t.^2 ); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
272 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
273 ## optimized equivalents of the above: |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
274 t1 = tx.^2; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
275 t2 = tx.*t1 - t1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
276 xb{2,2} = hx.*t2; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
277 t1 = t2 - t1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
278 xb{2,1} = hx.*(t1 + tx); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
279 t2 += t1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
280 xb{1,2} = -t2; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
281 xb{1,1} = t2 + 1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
282 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
283 t1 = ty.^2; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
284 t2 = ty.*t1 - t1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
285 yb{2,2} = hy.*t2; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
286 t1 = t2 - t1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
287 yb{2,1} = hy.*(t1 + ty); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
288 t2 += t1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
289 yb{1,2} = -t2; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
290 yb{1,1} = t2 + 1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
291 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
292 ZI = zeros (size (XI)); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
293 for i = 1:2 |
10549 | 294 for j = 1:2 |
295 zidx = sub2ind (size (Z), yidx+(j-1), xidx+(i-1)); | |
296 ZI += xb{1,i} .* yb{1,j} .* Z(zidx); | |
297 ZI += xb{2,i} .* yb{1,j} .* DX(zidx); | |
298 ZI += xb{1,i} .* yb{2,j} .* DY(zidx); | |
299 ZI += xb{2,i} .* yb{2,j} .* DXY(zidx); | |
300 endfor | |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
301 endfor |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
302 |
6702 | 303 endif |
5837 | 304 |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
305 if (! isempty (extrapval)) |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
306 ## set points outside the table to 'extrapval' |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
307 if (X (1) < X (end)) |
10549 | 308 if (Y (1) < Y (end)) |
309 ZI (XI < X(1,1) | XI > X(end) | YI < Y(1,1) | YI > Y(end)) = ... | |
310 extrapval; | |
311 else | |
312 ZI (XI < X(1) | XI > X(end) | YI < Y(end) | YI > Y(1)) = ... | |
313 extrapval; | |
314 endif | |
6979 | 315 else |
10549 | 316 if (Y (1) < Y (end)) |
317 ZI (XI < X(end) | XI > X(1) | YI < Y(1) | YI > Y(end)) = ... | |
318 extrapval; | |
319 else | |
320 ZI (XI < X(1,end) | XI > X(1) | YI < Y(end) | YI > Y(1)) = ... | |
321 extrapval; | |
322 endif | |
6979 | 323 endif |
324 endif | |
325 | |
6702 | 326 else |
5837 | 327 |
10780
6e7590d003dc
Fix bugs in interp2 (bug #29601)
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10635
diff
changeset
|
328 ## Check dimensions of X and Y |
6702 | 329 if (isvector (X) && isvector (Y)) |
330 X = X(:).'; | |
331 Y = Y(:); | |
11108
78a6016875ed
general/interp2.m: Fix input checks for cubic interpolation (bug #31352, part 1).
Gunnar Farneback <gunnar@lysator.liu.se>
parents:
10906
diff
changeset
|
332 if (!isequal ([length(Y), length(X)], size(Z))) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11108
diff
changeset
|
333 error ("interp2: X and Y size must match the dimensions of Z"); |
6702 | 334 endif |
335 elseif (!size_equal (X, Y)) | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11108
diff
changeset
|
336 error ("interp2: X and Y must be matrices of equal size"); |
6702 | 337 if (! size_equal (X, Z)) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11108
diff
changeset
|
338 error ("interp2: X and Y size must match the dimensions of Z"); |
6702 | 339 endif |
340 endif | |
5837 | 341 |
10780
6e7590d003dc
Fix bugs in interp2 (bug #29601)
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10635
diff
changeset
|
342 ## Check dimensions of XI and YI |
13149
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
343 if (isvector (XI) && isvector (YI) && ! size_equal (XI, YI)) |
10780
6e7590d003dc
Fix bugs in interp2 (bug #29601)
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10635
diff
changeset
|
344 XI = XI(:).'; |
6e7590d003dc
Fix bugs in interp2 (bug #29601)
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10635
diff
changeset
|
345 YI = YI(:); |
13149
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
346 [XI, YI] = meshgrid (XI, YI); |
6702 | 347 elseif (! size_equal (XI, YI)) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11108
diff
changeset
|
348 error ("interp2: XI and YI must be matrices of equal size"); |
6702 | 349 endif |
5837 | 350 |
6702 | 351 if (strcmp (method, "cubic")) |
13149
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
352 if (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
|
353 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
|
354 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
|
355 ## 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
|
356 ZI = zeros (size (X)); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
357 |
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
|
358 ## 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
|
359 inside = !(XI < X (1) | XI > X (end) | YI < Y (1) | YI > Y (end)); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
360 |
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
|
361 ## 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
|
362 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
|
363 YI = (rows (Z) - 1) * (YI - Y (1)) / (Y (end) - Y (1)) + 1; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
364 |
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
|
365 ## 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
|
366 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
|
367 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
|
368 |
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 ## 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
|
370 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
|
371 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
|
372 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
|
373 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
|
374 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
|
375 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
|
376 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
|
377 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
|
378 |
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 ## 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
|
380 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
|
381 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
|
382 + 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
|
383 + 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
|
384 + 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
|
385 + 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
|
386 + 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
|
387 + 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
|
388 + 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
|
389 + 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
|
390 + 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
|
391 + 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
|
392 + 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
|
393 + 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
|
394 + 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
|
395 + 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
|
396 + 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
|
397 ZI (!inside) = extrapval; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
398 |
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
|
399 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
|
400 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
|
401 endif |
5837 | 402 |
6702 | 403 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
|
404 if (isgriddata (XI) && isgriddata (YI')) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
405 ZI = __splinen__ ({Y(:,1).', X(1,:)}, Z, {YI(:,1), XI(1,:)}, extrapval, |
10549 | 406 "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
|
407 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
|
408 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
|
409 endif |
6702 | 410 else |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11108
diff
changeset
|
411 error ("interp2: interpolation METHOD not recognized"); |
6702 | 412 endif |
5837 | 413 |
6702 | 414 endif |
5837 | 415 endfunction |
416 | |
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
|
417 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
|
418 d1 = diff (X, 1, 1); |
10780
6e7590d003dc
Fix bugs in interp2 (bug #29601)
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10635
diff
changeset
|
419 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
|
420 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
|
421 |
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 ## 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
|
423 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
|
424 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
|
425 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
|
426 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
|
427 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
|
428 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
|
429 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
|
430 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
|
431 |
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 ## 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
|
433 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
|
434 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
|
435 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
|
436 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
|
437 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
|
438 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
|
439 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
|
440 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
|
441 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
|
442 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
|
443 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
|
444 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
|
445 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
|
446 |
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
|
447 |
5837 | 448 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
449 %! A = [13,-1,12;5,4,3;1,6,2]; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
450 %! x = [0,1,4]; y = [10,11,12]; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
451 %! xi = linspace (min(x), max(x), 17); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
452 %! yi = linspace (min(y), max(y), 26)'; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
453 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "linear")); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
454 %! [x,y] = meshgrid (x,y); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
455 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off; |
5837 | 456 |
457 %!demo | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
458 %! [x,y,A] = peaks (10); |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
459 %! x = x(1,:)'; y = y(:,1); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
460 %! xi = linspace (min(x), max(x), 41); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
461 %! yi = linspace (min(y), max(y), 41)'; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
462 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "linear")); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
463 %! [x,y] = meshgrid (x,y); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
464 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off; |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
465 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
466 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
467 %! A = [13,-1,12;5,4,3;1,6,2]; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
468 %! x = [0,1,4]; y = [10,11,12]; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
469 %! xi = linspace (min(x), max(x), 17); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
470 %! yi = linspace (min(y), max(y), 26)'; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
471 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "nearest")); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
472 %! [x,y] = meshgrid (x,y); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
473 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off; |
5837 | 474 |
6702 | 475 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
476 %! [x,y,A] = peaks (10); |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
477 %! x = x(1,:)'; y = y(:,1); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
478 %! xi = linspace (min(x), max(x), 41); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
479 %! yi = linspace (min(y), max(y), 41)'; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
480 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "nearest")); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
481 %! [x,y] = meshgrid (x,y); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
482 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off; |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
483 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
484 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
485 %! A = [13,-1,12;5,4,3;1,6,2]; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
486 %! x = [0,1,2]; y = [10,11,12]; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
487 %! xi = linspace (min(x), max(x), 17); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
488 %! yi = linspace (min(y), max(y), 26)'; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
489 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "pchip")); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
490 %! [x,y] = meshgrid (x,y); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
491 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off; |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
492 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
493 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
494 %! [x,y,A] = peaks (10); |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
495 %! x = x(1,:)'; y = y(:,1); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
496 %! xi = linspace (min(x), max(x), 41); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
497 %! yi = linspace (min(y), max(y), 41)'; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
498 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "pchip")); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
499 %! [x,y] = meshgrid (x,y); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
500 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off; |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
501 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
502 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
503 %! A = [13,-1,12;5,4,3;1,6,2]; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
504 %! x = [0,1,2]; y = [10,11,12]; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
505 %! xi = linspace (min(x), max(x), 17); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
506 %! yi = linspace (min(y), max(y), 26)'; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
507 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "cubic")); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
508 %! [x,y] = meshgrid (x,y); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
509 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off; |
5837 | 510 |
6702 | 511 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
512 %! [x,y,A] = peaks (10); |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
513 %! x = x(1,:)'; y = y(:,1); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
514 %! xi = linspace (min(x), max(x), 41); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
515 %! yi = linspace (min(y), max(y), 41)'; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
516 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "cubic")); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
517 %! [x,y] = meshgrid (x,y); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
518 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off; |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
519 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
520 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
521 %! A = [13,-1,12;5,4,3;1,6,2]; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
522 %! x = [0,1,2]; y = [10,11,12]; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
523 %! xi = linspace (min(x), max(x), 17); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
524 %! yi = linspace (min(y), max(y), 26)'; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
525 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "spline")); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
526 %! [x,y] = meshgrid (x,y); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
527 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off; |
6702 | 528 |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
529 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
530 %! [x,y,A] = peaks (10); |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
531 %! x = x(1,:)'; y = y(:,1); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
532 %! xi = linspace (min(x), max(x), 41); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
533 %! yi = linspace (min(y), max(y), 41)'; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
534 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "spline")); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
535 %! [x,y] = meshgrid (x,y); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
536 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off; |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
537 |
5837 | 538 %!test % simple test |
539 %! x = [1,2,3]; | |
540 %! y = [4,5,6,7]; | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
541 %! [X, Y] = meshgrid (x,y); |
5837 | 542 %! Orig = X.^2 + Y.^3; |
543 %! xi = [1.2,2, 1.5]; | |
544 %! yi = [6.2, 4.0, 5.0]'; | |
545 %! | |
546 %! Expected = ... | |
547 %! [243, 245.4, 243.9; | |
548 %! 65.6, 68, 66.5; | |
549 %! 126.6, 129, 127.5]; | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
550 %! Result = interp2 (x,y,Orig, xi, yi); |
5837 | 551 %! |
552 %! assert(Result, Expected, 1000*eps); | |
553 | |
554 %!test % 2^n form | |
555 %! x = [1,2,3]; | |
556 %! y = [4,5,6,7]; | |
557 %! [X, Y] = meshgrid(x,y); | |
558 %! Orig = X.^2 + Y.^3; | |
559 %! xi = [1:0.25:3]; yi = [4:0.25:7]'; | |
560 %! Expected = interp2(x,y,Orig, xi, yi); | |
561 %! Result = interp2(Orig,2); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
562 %! |
5837 | 563 %! assert(Result, Expected, 10*eps); |
564 | |
565 %!test % matrix slice | |
566 %! A = eye(4); | |
567 %! assert(interp2(A,[1:4],[1:4]),[1,1,1,1]); | |
568 | |
569 %!test % non-gridded XI,YI | |
570 %! A = eye(4); | |
571 %! assert(interp2(A,[1,2;3,4],[1,3;2,4]),[1,0;0,1]); | |
572 | |
573 %!test % for values outside of boundaries | |
574 %! x = [1,2,3]; | |
575 %! y = [4,5,6,7]; | |
576 %! [X, Y] = meshgrid(x,y); | |
577 %! Orig = X.^2 + Y.^3; | |
578 %! xi = [0,4]; | |
579 %! yi = [3,8]'; | |
6742 | 580 %! assert(interp2(x,y,Orig, xi, yi),[NA,NA;NA,NA]); |
5837 | 581 %! assert(interp2(x,y,Orig, xi, yi,'linear', 0),[0,0;0,0]); |
582 | |
583 %!test % for values at boundaries | |
584 %! A=[1,2;3,4]; | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
585 %! x=[0,1]; |
5837 | 586 %! y=[2,3]'; |
587 %! assert(interp2(x,y,A,x,y,'linear'), A); | |
588 %! assert(interp2(x,y,A,x,y,'nearest'), A); | |
589 | |
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
|
590 %!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
|
591 %! 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
|
592 %! 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
|
593 |
13149
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
594 %!shared z, zout, tol |
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
595 %! z = [1 3 5; 3 5 7; 5 7 9]; |
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
596 %! zout = [1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8; 5 6 7 8 9]; |
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
597 %! tol = 2 * eps; |
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
598 %!assert (interp2 (z), zout, tol); |
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
599 %!assert (interp2 (z, "linear"), zout, tol); |
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
600 %!assert (interp2 (z, "pchip"), zout, tol); |
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
601 %!assert (interp2 (z, "cubic"), zout, 10 * tol); |
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
602 %!assert (interp2 (z, "spline"), zout, tol); |
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
603 %!assert (interp2 (z, [2 3 1], [2 2 2]', "linear"), repmat ([5, 7, 3], [3, 1]), tol) |
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
604 %!assert (interp2 (z, [2 3 1], [2 2 2]', "pchip"), repmat ([5, 7, 3], [3, 1]), tol) |
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
605 %!assert (interp2 (z, [2 3 1], [2 2 2]', "cubic"), repmat ([5, 7, 3], [3, 1]), 10 * tol) |
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
606 %!assert (interp2 (z, [2 3 1], [2 2 2]', "spline"), repmat ([5, 7, 3], [3, 1]), tol) |
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
607 %!assert (interp2 (z, [2 3 1], [2 2 2], "linear"), [5 7 3], tol); |
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
608 %!assert (interp2 (z, [2 3 1], [2 2 2], "pchip"), [5 7 3], tol); |
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
609 %!assert (interp2 (z, [2 3 1], [2 2 2], "cubic"), [5 7 3], 10 * tol); |
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
610 %!assert (interp2 (z, [2 3 1], [2 2 2], "spline"), [5 7 3], tol); |