annotate scripts/general/interp2.m @ 31551:fd29c7a50a78 stable

maint: use commas, semicolons consistently with Octave conventions. * makeValidName.m: Remove %!test and move BIST %!asserts to column 1. * base64decode.m, base64encode.m, which.m, logm.m, uniquetol.m, perms.m: Delete semicolon (';') at end of %!assert BIST. * lin2mu.m, interp2.m, interpn.m, lsqnonneg.m, pqpnonneg.m, uniquetol.m, betainc.m, normalize.m: Add semicolon (';') to end of assert statement within %!test BIST. * __memoize__.m, tar_is_bsd.m, publish.m: Add semicolon (';') to line with keyword "persistent". * stft.m: Use comma (',') after "case" keyword when code immediately follows. * gallery.m: Align commas used in case statements in massive switch block. Remove unnecessary parentheses around a numeric case argument. * ranks.m: Remove semicolon (';') from case statemnt argument.
author Rik <rik@octave.org>
date Sat, 26 Nov 2022 06:32:08 -0800
parents a40c0b7aa376
children 597f3ee61a48
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30330
diff changeset
3 ## Copyright (C) 2000-2022 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
7 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
8 ## This file is part of Octave.
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23573
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23573
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22729
diff changeset
13 ## (at your option) any later version.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
14 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22729
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22729
diff changeset
18 ## GNU General Public License for more details.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
19 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23573
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
25
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20735
diff changeset
27 ## @deftypefn {} {@var{zi} =} interp2 (@var{x}, @var{y}, @var{z}, @var{xi}, @var{yi})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20735
diff changeset
28 ## @deftypefnx {} {@var{zi} =} interp2 (@var{z}, @var{xi}, @var{yi})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20735
diff changeset
29 ## @deftypefnx {} {@var{zi} =} interp2 (@var{z}, @var{n})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20735
diff changeset
30 ## @deftypefnx {} {@var{zi} =} interp2 (@var{z})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20735
diff changeset
31 ## @deftypefnx {} {@var{zi} =} interp2 (@dots{}, @var{method})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20735
diff changeset
32 ## @deftypefnx {} {@var{zi} =} interp2 (@dots{}, @var{method}, @var{extrap})
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
33 ##
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
34 ## Two-dimensional interpolation.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
35 ##
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
36 ## Interpolate reference data @var{x}, @var{y}, @var{z} to determine @var{zi}
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
37 ## at the coordinates @var{xi}, @var{yi}. The reference data @var{x}, @var{y}
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
38 ## can be matrices, as returned by @code{meshgrid}, in which case the sizes of
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
39 ## @var{x}, @var{y}, and @var{z} must be equal. If @var{x}, @var{y} are
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
40 ## vectors describing a grid then @code{length (@var{x}) == columns (@var{z})}
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
41 ## and @code{length (@var{y}) == rows (@var{z})}. In either case the input
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
42 ## data must be strictly monotonic.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
43 ##
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
44 ## If called without @var{x}, @var{y}, and just a single reference data matrix
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
45 ## @var{z}, the 2-D region
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
46 ## @code{@var{x} = 1:columns (@var{z}), @var{y} = 1:rows (@var{z})} is assumed.
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
47 ## This saves memory if the grid is regular and the distance between points is
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
48 ## not important.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
49 ##
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
50 ## If called with a single reference data matrix @var{z} and a refinement
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
51 ## value @var{n}, then perform interpolation over a grid where each original
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
52 ## interval has been recursively subdivided @var{n} times. This results in
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
53 ## @code{2^@var{n}-1} additional points for every interval in the original
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
54 ## grid. If @var{n} is omitted a value of 1 is used. As an example, the
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
55 ## interval [0,1] with @code{@var{n}==2} results in a refined interval with
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
56 ## points at [0, 1/4, 1/2, 3/4, 1].
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
57 ##
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
58 ## The interpolation @var{method} is one of:
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
59 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
60 ## @table @asis
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15467
diff changeset
61 ## @item @qcode{"nearest"}
6218
c1b66b74937d [project @ 2006-12-27 17:43:50 by jwe]
jwe
parents: 6157
diff changeset
62 ## Return the nearest neighbor.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
63 ##
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
64 ## @item @qcode{"linear"} (default)
6218
c1b66b74937d [project @ 2006-12-27 17:43:50 by jwe]
jwe
parents: 6157
diff changeset
65 ## Linear interpolation from nearest neighbors.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
66 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15467
diff changeset
67 ## @item @qcode{"pchip"}
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
68 ## Piecewise cubic Hermite interpolating polynomial---shape-preserving
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
69 ## interpolation with smooth first derivative.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
70 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15467
diff changeset
71 ## @item @qcode{"cubic"}
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
72 ## Cubic interpolation using a convolution kernel function---third order
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
73 ## method with smooth first derivative.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
74 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15467
diff changeset
75 ## @item @qcode{"spline"}
12175
2090995ca588 Correct en-dash,em-dash instances in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11589
diff changeset
76 ## Cubic spline interpolation---smooth first and second derivatives
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
77 ## throughout the curve.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
78 ## @end table
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
79 ##
19795
ca7599ae464d doc: Grammarcheck documentation ahead of 4.0 release.
Rik <rik@octave.org>
parents: 19697
diff changeset
80 ## @var{extrap} is a scalar number. It replaces values beyond the endpoints
24560
1c1adf6ab75d doc: Fix issues in geometry, polynomial, and interpolation chapters (bug #52835).
Rik <rik@octave.org>
parents: 23219
diff changeset
81 ## with @var{extrap}. Note that if @var{extrap} is used, @var{method} must
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
82 ## be specified as well. If @var{extrap} is omitted and the @var{method} is
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
83 ## @qcode{"spline"}, then the extrapolated values of the @qcode{"spline"} are
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
84 ## used. Otherwise the default @var{extrap} value for any other @var{method}
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
85 ## is @qcode{"NA"}.
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
86 ## @seealso{interp1, interp3, interpn, meshgrid}
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
87 ## @end deftypefn
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
88
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
89 function ZI = interp2 (varargin)
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
90
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
91 narginchk (1, 7);
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
92 nargs = nargin;
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
93
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
94 Z = X = Y = XI = YI = n = [];
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
95 method = "linear";
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
96 extrap = [];
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
97
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
98 ## Check for method and extrap
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
99 if (nargs > 1 && ischar (varargin{end-1}))
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
100 if (! isnumeric (varargin{end}) || ! isscalar (varargin{end}))
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
101 error ("interp2: EXTRAP must be a numeric scalar");
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
102 endif
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
103 extrap = varargin{end};
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
104 method = varargin{end-1};
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
105 nargs -= 2;
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
106 elseif (ischar (varargin{end}))
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
107 method = varargin{end};
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 19833
diff changeset
108 nargs -= 1;
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
109 endif
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
110 if (method(1) == "*")
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
111 warning ("interp2: ignoring unsupported '*' flag to METHOD");
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
112 method(1) = [];
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
113 endif
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
114 method = validatestring (method, ...
21173
5ecdcc6320d9 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 19833
diff changeset
115 {"nearest", "linear", "pchip", "cubic", "spline"});
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
116
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
117 ## Read numeric input
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
118 switch (nargs)
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
119 case 1
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
120 Z = varargin{1};
13149
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
121 n = 1;
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
122 case 2
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
123 [Z, n] = deal (varargin{1:nargs});
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
124 case 3
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
125 [Z, XI, YI] = deal (varargin{1:nargs});
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
126 case 5
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
127 [X, Y, Z, XI, YI] = deal (varargin{1:nargs});
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
128 otherwise
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
129 print_usage ();
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
130 endswitch
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
131
18641
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
132 ## Type checking
21173
5ecdcc6320d9 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 19833
diff changeset
133 if (! isnumeric (Z) || isscalar (Z) || ! ismatrix (Z))
18664
900b524d9072 interp2: Verify Z matrix is 2-D (bug #41267).
Rik <rik@octave.org>
parents: 18641
diff changeset
134 error ("interp2: Z must be a 2-D matrix");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
135 endif
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
136 if (! isempty (n) && ! (isscalar (n) && n >= 0 && n == fix (n)))
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
137 error ("interp2: N must be an integer >= 0");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
138 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
139
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
140 ## Define X, Y, XI, YI if needed
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
141 [zr, zc] = size (Z);
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
142 if (isempty (X))
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
143 X = 1:zc;
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
144 Y = 1:zr;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
145 endif
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
146 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
147 error ("interp2: X, Y must be numeric matrices");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
148 endif
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
149 if (! isempty (n))
13149
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
150 ## 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
151 p = 2^n;
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
152 XI = (p:p*zc)/p;
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
153 YI = (p:p*zr).'/p;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
154 endif
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
155 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
156 error ("interp2: XI, YI must be numeric");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
157 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
158
18641
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
159 if (isvector (X) && isvector (Y))
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
160 X = X(:); Y = Y(:);
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
161 elseif (size_equal (X, Y))
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
162 X = X(1,:).'; Y = Y(:,1);
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
163 else
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
164 error ("interp2: X and Y must be matrices of equal size");
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
165 endif
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
166 if (columns (Z) != length (X) || rows (Z) != length (Y))
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
167 error ("interp2: X and Y size must match the dimensions of Z");
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
168 endif
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
169 dx = diff (X);
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
170 if (all (dx < 0))
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
171 X = flipud (X);
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
172 Z = fliplr (Z);
18641
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
173 elseif (any (dx <= 0))
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
174 error ("interp2: X must be strictly monotonic");
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
175 endif
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
176 dy = diff (Y);
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
177 if (all (dy < 0))
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
178 Y = flipud (Y);
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
179 Z = flipud (Z);
18641
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
180 elseif (any (dy <= 0))
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
181 error ("interp2: Y must be strictly monotonic");
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
182 endif
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
183
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
184 if (strcmp (method, "cubic") && (rows (Z) < 3 || columns (Z) < 3))
30718
95ee9b9605cc maint: Tweaks to cset 98484425bd1b (interp2) for Octave coding conventions.
Rik <rik@octave.org>
parents: 30714
diff changeset
185 warning (["interp2: cubic requires at least 3 points in each " ...
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
186 "dimension. Falling back to linear interpolation."]);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
187 method = "linear";
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
188 endif
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
189
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
190 if (any (strcmp (method, {"nearest", "linear", "pchip"})))
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
191
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
192 ## If Xi and Yi are vectors of different orientation build a grid
22729
66d73a5a48b0 interp2.m: Clean up code.
Rik <rik@octave.org>
parents: 22727
diff changeset
193 if ((isrow (XI) && iscolumn (YI)) || (iscolumn (XI) && isrow (YI)))
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
194 [XI, YI] = meshgrid (XI, YI);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
195 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
196 error ("interp2: XI and YI must be matrices of equal size");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
197 endif
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
198
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
199 ## if XI, YI are vectors, X and Y should share their orientation.
22729
66d73a5a48b0 interp2.m: Clean up code.
Rik <rik@octave.org>
parents: 22727
diff changeset
200 if (isrow (XI))
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
201 if (rows (X) != 1)
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
202 X = X.';
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
203 endif
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
204 if (rows (Y) != 1)
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
205 Y = Y.';
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
206 endif
22729
66d73a5a48b0 interp2.m: Clean up code.
Rik <rik@octave.org>
parents: 22727
diff changeset
207 elseif (iscolumn (XI))
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
208 if (columns (X) != 1)
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
209 X = X.';
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
210 endif
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
211 if (columns (Y) != 1)
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
212 Y = Y.';
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
213 endif
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
214 endif
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
215
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
216 xidx = lookup (X, XI, "lr");
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
217 yidx = lookup (Y, YI, "lr");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
218
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
219 if (strcmp (method, "linear"))
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
220 ## each quad satisfies the equation z(x,y)=a+b*x+c*y+d*xy
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
221 ##
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
222 ## a-b
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
223 ## | |
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
224 ## c-d
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
225 a = Z(1:(zr - 1), 1:(zc - 1));
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
226 b = Z(1:(zr - 1), 2:zc) - a;
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
227 c = Z(2:zr, 1:(zc - 1)) - a;
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
228 d = Z(2:zr, 2:zc) - a - b - c;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
229
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
230 ## scale XI, YI values to a 1-spaced grid
10326
ade59ae10e80 slight optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 10320
diff changeset
231 Xsc = (XI - X(xidx)) ./ (diff (X)(xidx));
ade59ae10e80 slight optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 10320
diff changeset
232 Ysc = (YI - Y(yidx)) ./ (diff (Y)(yidx));
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
233
31253
a40c0b7aa376 maint: changes to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 30802
diff changeset
234 ## Get 2-D index.
10328
2210d3070543 further memory optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 10326
diff changeset
235 idx = sub2ind (size (a), yidx, xidx);
31253
a40c0b7aa376 maint: changes to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 30802
diff changeset
236 ## Dispose of the 1-D indices at this point to save memory.
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
237 clear xidx yidx;
10328
2210d3070543 further memory optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 10326
diff changeset
238
22727
125391edc71b interp2.m: Re-orient vector/vector indexing in "linear" to fix output sizie (bug #49506).
Rik <rik@octave.org>
parents: 22489
diff changeset
239 ## Apply plane equation
125391edc71b interp2.m: Re-orient vector/vector indexing in "linear" to fix output sizie (bug #49506).
Rik <rik@octave.org>
parents: 22489
diff changeset
240 ## Handle case where idx and coefficients are both vectors and resulting
125391edc71b interp2.m: Re-orient vector/vector indexing in "linear" to fix output sizie (bug #49506).
Rik <rik@octave.org>
parents: 22489
diff changeset
241 ## coeff(idx) follows orientation of coeff, rather than that of idx.
125391edc71b interp2.m: Re-orient vector/vector indexing in "linear" to fix output sizie (bug #49506).
Rik <rik@octave.org>
parents: 22489
diff changeset
242 forient = @(x) reshape (x, size (idx));
125391edc71b interp2.m: Re-orient vector/vector indexing in "linear" to fix output sizie (bug #49506).
Rik <rik@octave.org>
parents: 22489
diff changeset
243 ZI = forient (a(idx)) ...
125391edc71b interp2.m: Re-orient vector/vector indexing in "linear" to fix output sizie (bug #49506).
Rik <rik@octave.org>
parents: 22489
diff changeset
244 + forient (b(idx)) .* Xsc ...
125391edc71b interp2.m: Re-orient vector/vector indexing in "linear" to fix output sizie (bug #49506).
Rik <rik@octave.org>
parents: 22489
diff changeset
245 + forient (c(idx)) .* Ysc ...
125391edc71b interp2.m: Re-orient vector/vector indexing in "linear" to fix output sizie (bug #49506).
Rik <rik@octave.org>
parents: 22489
diff changeset
246 + forient (d(idx)) .* Xsc.*Ysc;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
247
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
248 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
249 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
250 jj = (YI - Y(yidx) >= Y(yidx + 1) - YI);
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
251 idx = sub2ind (size (Z), yidx+jj, xidx+ii);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
252 ZI = Z(idx);
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
253
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
254 elseif (strcmp (method, "pchip"))
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
255
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
256 if (length (X) < 2 || length (Y) < 2)
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
257 error ("interp2: pchip requires at least 2 points in each dimension");
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
258 endif
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
259
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
260 ## first order derivatives
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
261 DX = __pchip_deriv__ (X, Z, 2);
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
262 DY = __pchip_deriv__ (Y, Z, 1);
30661
27566803b3b1 interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
263 ## Compute mixed derivatives row-wise and column-wise. Use the average.
30718
95ee9b9605cc maint: Tweaks to cset 98484425bd1b (interp2) for Octave coding conventions.
Rik <rik@octave.org>
parents: 30714
diff changeset
264 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
265
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
266 ## do the bicubic interpolation
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
267 hx = diff (X); hx = hx(xidx);
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
268 hy = diff (Y); hy = hy(yidx);
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 tx = (XI - X(xidx)) ./ hx;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
271 ty = (YI - Y(yidx)) ./ hy;
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 ## construct the cubic hermite base functions in x, y
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
274
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
275 ## formulas:
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
276 ## 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
277 ## 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
278 ## b{1,2} = (-2*t.^3 + 3*t.^2 );
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
279 ## b{2,2} = h.*( t.^3 - t.^2 );
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
280
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
281 ## optimized equivalents of the above:
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
282 t1 = tx.^2;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
283 t2 = tx.*t1 - t1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
284 xb{2,2} = hx.*t2;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
285 t1 = t2 - t1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
286 xb{2,1} = hx.*(t1 + tx);
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
287 t2 += t1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
288 xb{1,2} = -t2;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
289 xb{1,1} = t2 + 1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
290
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
291 t1 = ty.^2;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
292 t2 = ty.*t1 - t1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
293 yb{2,2} = hy.*t2;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
294 t1 = t2 - t1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
295 yb{2,1} = hy.*(t1 + ty);
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
296 t2 += t1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
297 yb{1,2} = -t2;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
298 yb{1,1} = t2 + 1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
299
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
300 ZI = zeros (size (XI));
30663
9b8c74d85fa7 interp2.m: Avoid using i and j as loop variables (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30661
diff changeset
301 for ix = 1:2
9b8c74d85fa7 interp2.m: Avoid using i and j as loop variables (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30661
diff changeset
302 for iy = 1:2
9b8c74d85fa7 interp2.m: Avoid using i and j as loop variables (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30661
diff changeset
303 zidx = sub2ind (size (Z), yidx+(iy-1), xidx+(ix-1));
9b8c74d85fa7 interp2.m: Avoid using i and j as loop variables (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30661
diff changeset
304 ZI += xb{1,ix} .* yb{1,iy} .* Z(zidx);
9b8c74d85fa7 interp2.m: Avoid using i and j as loop variables (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30661
diff changeset
305 ZI += xb{2,ix} .* yb{1,iy} .* DX(zidx);
9b8c74d85fa7 interp2.m: Avoid using i and j as loop variables (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30661
diff changeset
306 ZI += xb{1,ix} .* yb{2,iy} .* DY(zidx);
9b8c74d85fa7 interp2.m: Avoid using i and j as loop variables (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30661
diff changeset
307 ZI += xb{2,ix} .* yb{2,iy} .* DXY(zidx);
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
308 endfor
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
309 endfor
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
310
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
311 endif
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
312
30718
95ee9b9605cc maint: Tweaks to cset 98484425bd1b (interp2) for Octave coding conventions.
Rik <rik@octave.org>
parents: 30714
diff changeset
313 else # cubic or spline methods
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
314
10780
6e7590d003dc Fix bugs in interp2 (bug #29601)
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10635
diff changeset
315 ## Check dimensions of XI and YI
13149
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
316 if (isvector (XI) && isvector (YI) && ! size_equal (XI, YI))
18641
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
317 XI = XI(:).'; YI = YI(:);
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
318 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
319 error ("interp2: XI and YI must be matrices of equal size");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
320 endif
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
321
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
322 if (strcmp (method, "spline"))
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
323 if (isgriddata (XI) && isgriddata (YI.'))
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
324 ZI = __splinen__ ({Y, X}, Z, {YI(:,1), XI(1,:)}, extrap, "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
325 else
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
326 error ("interp2: XI, YI must have uniform spacing ('meshgrid' format)");
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
327 endif
30718
95ee9b9605cc maint: Tweaks to cset 98484425bd1b (interp2) for Octave coding conventions.
Rik <rik@octave.org>
parents: 30714
diff changeset
328 return; # spline doesn't use extrapolation value (MATLAB compatibility)
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
329 elseif (strcmp (method, "cubic"))
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
330 ## reduce to vectors if interpolation points are a meshgrid
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
331 if (size_equal (XI, YI) && all (all (XI(1, :) == XI & YI(:, 1) == YI)))
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
332 XI = XI(1, :);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
333 YI = YI(:, 1);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
334 endif
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
335
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
336 ## make X a row vector
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
337 X = X.';
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
338
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
339 ## quadratic padding + additional zeros for the special case of copying
30718
95ee9b9605cc maint: Tweaks to cset 98484425bd1b (interp2) for Octave coding conventions.
Rik <rik@octave.org>
parents: 30714
diff changeset
340 ## the last line (like x=1:5, xi=5, requires to have indices 6 and 7)
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
341 row_1 = 3*Z(1, :, :) - 3*Z(2, :, :) + Z(3, :, :);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
342 row_end = 3*Z(end, :, :) - 3*Z(end-1, :, :) + Z(end-2, :, :);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
343 ZI = [3*row_1(:, 1, :) - 3*row_1(:, 2, :) + row_1(:, 3, :), ...
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
344 row_1, ...
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
345 3*row_1(:, end, :) - 3*row_1(:, end-1, :) + row_1(:, end-2, :), ...
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
346 0;
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
347 #
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
348 3*Z(:, 1, :) - 3*Z(:, 2, :) + Z(:, 3, :), ...
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
349 Z, ...
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
350 3*Z(:, end, :) - 3*Z(:, end-1, :) + Z(:, end-2, :), ...
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
351 zeros(rows (Z), 1, size (Z, 3));
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
352 #
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
353 3*row_end(:, 1, :) - 3*row_end(:, 2, :) + row_end(:, 3, :), ...
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
354 row_end, ...
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
355 3*row_end(:, end, :) - 3*row_end(:, end-1, :) + row_end(:, end-2, :), ...
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
356 0;
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
357 zeros(1, columns (Z) + 3, size (Z, 3))];
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
358
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
359 ## interpolate
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
360 if (isrow (XI) && iscolumn (YI))
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
361 ZI = conv_interp_vec (ZI, Y, YI, @cubic, [-2, 2], 1);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
362 ZI = conv_interp_vec (ZI, X, XI, @cubic, [-2, 2], 2);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
363 else
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
364 ZI = conv_interp_pairs (ZI, X, Y, XI, YI, @cubic, [-2, 2]);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
365 endif
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
366 endif
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
367 endif
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
368
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19795
diff changeset
369 ## extrapolation 'extrap'
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
370 if (isempty (extrap))
30661
27566803b3b1 interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
371 if (iscomplex (Z))
27566803b3b1 interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
372 extrap = complex (NA, NA);
27566803b3b1 interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
373 else
27566803b3b1 interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
374 extrap = NA;
27566803b3b1 interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
375 endif
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
376 endif
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19795
diff changeset
377
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
378 if (X(1) < X(end))
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
379 if (Y(1) < Y(end))
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
380 ZI(XI < X(1,1) | XI > X(end) | YI < Y(1,1) | YI > Y(end)) = extrap;
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
381 else
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
382 ZI(XI < X(1) | XI > X(end) | YI < Y(end) | YI > Y(1)) = extrap;
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
383 endif
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
384 else
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
385 if (Y(1) < Y(end))
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
386 ZI(XI < X(end) | XI > X(1) | YI < Y(1) | YI > Y(end)) = extrap;
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
387 else
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
388 ZI(XI < X(1,end) | XI > X(1) | YI < Y(end) | YI > Y(1)) = extrap;
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
389 endif
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
390 endif
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
391
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
392 endfunction
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
393
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
394 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
395 d1 = diff (X, 1, 1);
22729
66d73a5a48b0 interp2.m: Clean up code.
Rik <rik@octave.org>
parents: 22727
diff changeset
396 b = ! any (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
397 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
398
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
399 ## cubic convolution kernel with a = -0.5 for MATLAB compatibility.
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
400 function w = cubic (h)
30718
95ee9b9605cc maint: Tweaks to cset 98484425bd1b (interp2) for Octave coding conventions.
Rik <rik@octave.org>
parents: 30714
diff changeset
401
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
402 absh = abs (h);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
403 absh01 = absh <= 1;
30718
95ee9b9605cc maint: Tweaks to cset 98484425bd1b (interp2) for Octave coding conventions.
Rik <rik@octave.org>
parents: 30714
diff changeset
404 absh12 = absh <= 2 & ! absh01;
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
405 absh_sqr = absh .* absh;
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
406 absh_cube = absh_sqr .* absh;
30718
95ee9b9605cc maint: Tweaks to cset 98484425bd1b (interp2) for Octave coding conventions.
Rik <rik@octave.org>
parents: 30714
diff changeset
407 w = ... # for |h| <= 1
95ee9b9605cc maint: Tweaks to cset 98484425bd1b (interp2) for Octave coding conventions.
Rik <rik@octave.org>
parents: 30714
diff changeset
408 (1.5 * absh_cube - 2.5 * absh_sqr + 1) .* absh01 ...
95ee9b9605cc maint: Tweaks to cset 98484425bd1b (interp2) for Octave coding conventions.
Rik <rik@octave.org>
parents: 30714
diff changeset
409 ... # for 1 < |h| <= 2
95ee9b9605cc maint: Tweaks to cset 98484425bd1b (interp2) for Octave coding conventions.
Rik <rik@octave.org>
parents: 30714
diff changeset
410 + (-0.5 * absh_cube + 2.5 * absh_sqr - 4 * absh + 2) .* absh12;
95ee9b9605cc maint: Tweaks to cset 98484425bd1b (interp2) for Octave coding conventions.
Rik <rik@octave.org>
parents: 30714
diff changeset
411
95ee9b9605cc maint: Tweaks to cset 98484425bd1b (interp2) for Octave coding conventions.
Rik <rik@octave.org>
parents: 30714
diff changeset
412 endfunction
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
413
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
414 ## bicubic interpolation of full matrix in one direction with vector
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
415 function out = conv_interp_vec (Z, XY, XIYI, kernel, kernel_bounds, axis)
30718
95ee9b9605cc maint: Tweaks to cset 98484425bd1b (interp2) for Octave coding conventions.
Rik <rik@octave.org>
parents: 30714
diff changeset
416
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
417 ## allocate output
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
418 out_shape = size (Z);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
419 out_shape(axis) = length (XIYI);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
420 out = zeros (out_shape);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
421
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
422 ## get indexes and distances h
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
423 spread = abs (XY(1) - XY(2));
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
424 idx = lookup (XY, XIYI, "l");
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
425 h = (XIYI - XY(idx)) / spread;
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
426 idx += -kernel_bounds(1) - 1; # apply padding for indexes
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
427
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
428 ## interpolate
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
429 for shift = kernel_bounds(1)+1 : kernel_bounds(2)
30718
95ee9b9605cc maint: Tweaks to cset 98484425bd1b (interp2) for Octave coding conventions.
Rik <rik@octave.org>
parents: 30714
diff changeset
430 if (axis == 1)
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
431 out += Z(idx + shift, :) .* kernel (shift - h);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
432 else
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
433 out += Z(:, idx + shift) .* kernel (shift - h);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
434 endif
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
435 endfor
30718
95ee9b9605cc maint: Tweaks to cset 98484425bd1b (interp2) for Octave coding conventions.
Rik <rik@octave.org>
parents: 30714
diff changeset
436
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
437 endfunction
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
438
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
439 ## bicubic interpolation of arbitrary XI-YI-pairs
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
440 function out = conv_interp_pairs (Z, X, Y, XI, YI, kernel, kernel_bounds)
30718
95ee9b9605cc maint: Tweaks to cset 98484425bd1b (interp2) for Octave coding conventions.
Rik <rik@octave.org>
parents: 30714
diff changeset
441
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
442 spread_x = abs (X(1, 1) - X(1, 2));
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
443 spread_y = abs (Y(1, 1) - Y(2, 1));
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
444 idx_x = lookup (X, XI, "l");
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
445 idx_y = lookup (Y, YI, "l");
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
446 h_x = (XI - reshape (X(idx_x), size (idx_x))) / spread_x;
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
447 h_y = (YI - reshape (Y(idx_y), size (idx_y))) / spread_y;
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
448
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
449 # adjust indexes for padding
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
450 idx_x += -kernel_bounds(1) - 1;
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
451 idx_y += -kernel_bounds(1) - 1;
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
452
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
453 shifts = kernel_bounds(1)+1 : kernel_bounds(2);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
454 [SX(1,1,:,:), SY(1,1,:,:)] = meshgrid (shifts, shifts);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
455 pixels = Z(sub2ind (size (Z), idx_y + SY, idx_x + SX));
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
456 kernel_y = kernel (reshape (shifts, 1, 1, [], 1) - h_y);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
457 kernel_x = kernel (reshape (shifts, 1, 1, 1, []) - h_x);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
458 out_x = sum (pixels .* kernel_x, 4);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
459 out = sum (out_x .* kernel_y, 3);
30718
95ee9b9605cc maint: Tweaks to cset 98484425bd1b (interp2) for Octave coding conventions.
Rik <rik@octave.org>
parents: 30714
diff changeset
460
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
461 endfunction
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
462
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
463
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
464 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
465 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
466 %! colormap ("default");
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];
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
468 %! x = [0,1,4]; y = [10,11,12];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
469 %! xi = linspace (min (x), max (x), 17);
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
470 %! yi = linspace (min (y), max (y), 26).';
14237
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, "linear"));
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);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
473 %! hold on; plot3 (x,y,A,"b*"); hold off;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
474
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
475 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
476 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
477 %! colormap ("default");
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 %! [x,y,A] = peaks (10);
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
479 %! x = x(1,:).'; y = y(:,1);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
480 %! xi = linspace (min (x), max (x), 41);
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
481 %! yi = linspace (min (y), max (y), 41).';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
482 %! 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
483 %! [x,y] = meshgrid (x,y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
484 %! 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
485
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
486 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
487 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
488 %! colormap ("default");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
489 %! A = [13,-1,12;5,4,3;1,6,2];
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
490 %! x = [0,1,4]; y = [10,11,12];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
491 %! xi = linspace (min (x), max (x), 17);
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
492 %! yi = linspace (min (y), max (y), 26).';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
493 %! 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
494 %! [x,y] = meshgrid (x,y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
495 %! hold on; plot3 (x,y,A,"b*"); hold off;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
496
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
497 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
498 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
499 %! colormap ("default");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
500 %! [x,y,A] = peaks (10);
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
501 %! x = x(1,:).'; y = y(:,1);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
502 %! xi = linspace (min (x), max (x), 41);
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
503 %! yi = linspace (min (y), max (y), 41).';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
504 %! 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
505 %! [x,y] = meshgrid (x,y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
506 %! 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
507
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
508 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
509 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
510 %! colormap ("default");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
511 %! A = [13,-1,12;5,4,3;1,6,2];
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
512 %! x = [0,1,2]; y = [10,11,12];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
513 %! xi = linspace (min (x), max (x), 17);
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
514 %! yi = linspace (min (y), max (y), 26).';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
515 %! 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
516 %! [x,y] = meshgrid (x,y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
517 %! 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
518
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
519 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
520 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
521 %! colormap ("default");
14237
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,y,A] = peaks (10);
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
523 %! x = x(1,:).'; y = y(:,1);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
524 %! xi = linspace (min (x), max (x), 41);
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
525 %! yi = linspace (min (y), max (y), 41).';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
526 %! 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
527 %! [x,y] = meshgrid (x,y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
528 %! 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
529
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
530 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
531 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
532 %! colormap ("default");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
533 %! A = [13,-1,12;5,4,3;1,6,2];
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
534 %! x = [0,1,2]; y = [10,11,12];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
535 %! xi = linspace (min (x), max (x), 17);
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
536 %! yi = linspace (min (y), max (y), 26).';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
537 %! 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
538 %! [x,y] = meshgrid (x,y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
539 %! hold on; plot3 (x,y,A,"b*"); hold off;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
540
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
541 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
542 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
543 %! colormap ("default");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
544 %! [x,y,A] = peaks (10);
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
545 %! x = x(1,:).'; y = y(:,1);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
546 %! xi = linspace (min (x), max (x), 41);
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
547 %! yi = linspace (min (y), max (y), 41).';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
548 %! 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
549 %! [x,y] = meshgrid (x,y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
550 %! 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
551
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
552 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
553 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
554 %! colormap ("default");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
555 %! A = [13,-1,12;5,4,3;1,6,2];
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
556 %! x = [0,1,2]; y = [10,11,12];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
557 %! xi = linspace (min (x), max (x), 17);
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
558 %! yi = linspace (min (y), max (y), 26).';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
559 %! 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
560 %! [x,y] = meshgrid (x,y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
561 %! hold on; plot3 (x,y,A,"b*"); hold off;
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
562
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
563 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
564 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
565 %! colormap ("default");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
566 %! [x,y,A] = peaks (10);
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
567 %! x = x(1,:).'; y = y(:,1);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
568 %! xi = linspace (min (x), max (x), 41);
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
569 %! yi = linspace (min (y), max (y), 41).';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
570 %! 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
571 %! [x,y] = meshgrid (x,y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
572 %! 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
573
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
574 %!shared x, y, orig, xi, yi, expected
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
575 %!test # simple test
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
576 %! x = [1,2,3];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
577 %! y = [4,5,6,7];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
578 %! [X, Y] = meshgrid (x, y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
579 %! orig = X.^2 + Y.^3;
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
580 %! xi = [0.8, 1.2, 2.0, 1.5];
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
581 %! yi = [6.2, 4.0, 5.0, 7.1].';
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
582 %!
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
583 %! # check nearest neighbor
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
584 %! expected = ...
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
585 %! [NA, 217, 220, 220;
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
586 %! NA, 65, 68, 68;
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
587 %! NA, 126, 129, 129;
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
588 %! NA, NA, NA, NA];
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
589 %! result = interp2 (x, y, orig, xi, yi, "nearest");
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
590 %! assert (result, expected);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
591 %!
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
592 %! # check invariance of translation
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
593 %! result = interp2 (x+3, y-7, orig, xi+3, yi-7, "nearest");
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
594 %! assert (result, expected);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
595 %!
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
596 %! # check invariance of scaling
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
597 %! result = interp2 (x*3, y*(-7), orig, xi*3, yi*(-7), "nearest");
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
598 %! assert (result, expected);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
599 %!
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
600 %! # check interpolation with index pairs
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
601 %! result = interp2 (x, y, orig, xi(2:4), yi(1:3).', "nearest");
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
602 %! assert (result, expected(sub2ind(size(expected), 1:3, 2:4)));
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
603 %!
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
604 %! # check bilinear interpolation
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
605 %! expected = ...
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
606 %! [NA, 243, 245.4, 243.9;
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
607 %! NA, 65.6, 68, 66.5;
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
608 %! NA, 126.6, 129, 127.5;
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
609 %! NA, NA, NA, NA];
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
610 %! result = interp2 (x, y, orig, xi, yi);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
611 %! assert (result, expected, 1000*eps);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
612 %!
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
613 %! # check invariance of translation
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
614 %! result = interp2 (x+3, y-7, orig, xi+3, yi-7);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
615 %! assert (result, expected, 1000*eps);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
616 %!
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
617 %! # check invariance of scaling
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
618 %! result = interp2 (x*3, y*(-7), orig, xi*3, yi*(-7));
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
619 %! assert (result, expected, 1000*eps);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
620 %!
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
621 %! # check interpolation with index pairs
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
622 %! result = interp2 (x, y, orig, xi(2:4), yi(1:3).');
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
623 %! assert (result, expected(sub2ind(size(expected), 1:3, 2:4)), 1000*eps);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
624 %!
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
625 %! # check spline interpolation
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
626 %! expected = ...
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
627 %! [238.968, 239.768, 242.328, 240.578;
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
628 %! 64.64, 65.44, 68, 66.25;
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
629 %! 125.64, 126.44, 129, 127.25;
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
630 %! 358.551, 359.351, 361.911, 360.161];
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
631 %! result = interp2 (x, y, orig, xi, yi, "spline");
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
632 %! assert (result, expected, 1000*eps);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
633 %!
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
634 %! # check invariance of translation
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
635 %! result = interp2 (x+3, y-7, orig, xi+3, yi-7, "spline");
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
636 %! assert (result, expected, 1000*eps);
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
637 %!
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
638 %! # check invariance of scaling
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
639 %! result = interp2 (x*3, y*(-7), orig, xi*3, yi*(-7), "spline");
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
640 %! assert (result, expected, 1000*eps);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
641 %!
30802
836104321759 * interp2.m: Use 'test <BUG-ID>' instead of 'xtest'.
John W. Eaton <jwe@octave.org>
parents: 30718
diff changeset
642 %!test <62133>
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
643 %! # FIXME: spline interpolation does not support index pairs, Matlab does.
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
644 %! result = interp2 (x, y, orig, xi(2:4), yi(1:3).', "spline");
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
645 %! assert (result, expected(sub2ind(size(expected), 1:3, 2:4)), 1000*eps);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
646 %!
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
647 %!test <*61754>
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
648 %! # check bicubic interpolation
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
649 %! expected = ...
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
650 %! [NA, 239.96, 242.52, 240.77;
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
651 %! NA, 65.44, 68, 66.25;
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
652 %! NA, 126.44, 129, 127.25;
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
653 %! NA, NA, NA, NA];
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
654 %! result = interp2 (x, y, orig, xi, yi, "cubic");
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
655 %! assert (result, expected, 10000*eps);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
656 %!
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
657 %! # check invariance of translation
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
658 %! result = interp2 (x+3, y-7, orig, xi+3, yi-7, "cubic");
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
659 %! assert (result, expected, 10000*eps);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
660 %!
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
661 %! # check invariance of scaling
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
662 %! result = interp2 (x*3, y*(-7), orig, xi*3, yi*(-7), "cubic");
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
663 %! assert (result, expected, 10000*eps);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
664 %!
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
665 %! # check interpolation with index pairs
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
666 %! result = interp2 (x, y, orig, xi(2:4), yi(1:3).', "cubic");
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
667 %! assert (result, expected(sub2ind(size(expected), 1:3, 2:4)), 10000*eps);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
668
30661
27566803b3b1 interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
669 ## Test that interpolating a complex matrix is equivalent to interpolating its
27566803b3b1 interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
670 ## real and imaginary parts separately.
30689
4b367bf5eb16 Fix __pchip_deriv__ for complex matrix (bug #61863, bug #61903)
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30663
diff changeset
671 %!test <*61863>
30661
27566803b3b1 interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
672 %! xi = [2.5, 3.5];
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
673 %! yi = [0.5, 1.5].';
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
674 %! orig = rand (4, 3) + 1i * rand (4, 3);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
675 %! for method = {"nearest", "linear", "pchip", "cubic", "spline"}
30661
27566803b3b1 interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
676 %! interp_complex = interp2 (orig, xi, yi, method{1});
27566803b3b1 interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
677 %! interp_real = interp2 (real (orig), xi, yi, method{1});
27566803b3b1 interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
678 %! interp_imag = interp2 (imag (orig), xi, yi, method{1});
31551
fd29c7a50a78 maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents: 31253
diff changeset
679 %! assert (real (interp_complex), interp_real);
fd29c7a50a78 maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents: 31253
diff changeset
680 %! assert (imag (interp_complex), interp_imag);
30661
27566803b3b1 interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
681 %! endfor
27566803b3b1 interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
682
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
683 %!test # 2^n refinement form
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
684 %! x = [1,2,3];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
685 %! y = [4,5,6,7];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
686 %! [X, Y] = meshgrid (x, y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
687 %! orig = X.^2 + Y.^3;
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
688 %! xi = [1:0.25:3]; yi = [4:0.25:7].';
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
689 %! expected = interp2 (x,y,orig, xi, yi);
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
690 %! result = interp2 (orig, 2);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
691 %!
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
692 %! assert (result, expected, 10*eps);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
693
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
694 %!test # matrix slice
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
695 %! A = eye (4);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
696 %! assert (interp2 (A,[1:4],[1:4]), [1,1,1,1]);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
697
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
698 %!test # non-gridded XI,YI
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
699 %! A = eye (4);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
700 %! assert (interp2 (A,[1,2;3,4],[1,3;2,4]), [1,0;0,1]);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
701
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
702 %!test # for values outside of boundaries
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
703 %! x = [1,2,3];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
704 %! y = [4,5,6,7];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
705 %! [X, Y] = meshgrid (x,y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
706 %! orig = X.^2 + Y.^3;
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
707 %! xi = [0,4];
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
708 %! yi = [3,8].';
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
709 %! assert (interp2 (x,y,orig, xi, yi), [NA,NA;NA,NA]);
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
710 %! assert (interp2 (x,y,orig, xi, yi,"linear", 0), [0,0;0,0]);
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
711 %! assert (interp2 (x,y,orig, xi, yi,"linear", 2), [2,2;2,2]);
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
712 %! assert (interp2 (x,y,orig, xi, yi,"spline", 2), [2,2;2,2]);
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
713 %! assert (interp2 (x,y,orig, xi, yi,"linear", 0+1i), [0+1i,0+1i;0+1i,0+1i]);
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
714 %! assert (interp2 (x,y,orig, xi, yi,"spline"), [27,43;512,528]);
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
715 %! assert (interp2 (x,y,orig, xi, yi,"cubic"), [NA,NA;NA,NA]);
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
716 %! assert (interp2 (x,y,orig, xi, yi,"cubic", 2), [2,2;2,2]);
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
717
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
718 %!test # for values at boundaries
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
719 %! A = [1,2;3,4];
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
720 %! x = [0,1];
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
721 %! y = [2,3].';
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
722 %! assert (interp2 (x,y,A,x,y,"linear"), A);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
723 %! assert (interp2 (x,y,A,x,y,"nearest"), A);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
724
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
725 %!test # for Matlab-compatible rounding for '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
726 %! X = meshgrid (1:4);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
727 %! assert (interp2 (X, 2.5, 2.5, "nearest"), 3);
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
728
22489
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 21317
diff changeset
729 ## re-order monotonically decreasing
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
730 %!assert <*41838> (interp2 ([1 2 3], [3 2 1], magic (3), 2.5, 3), 3.5)
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
731 %!assert <*41838> (interp2 ([3 2 1], [1 2 3], magic (3), 1.5, 1), 3.5)
18641
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
732
22727
125391edc71b interp2.m: Re-orient vector/vector indexing in "linear" to fix output sizie (bug #49506).
Rik <rik@octave.org>
parents: 22489
diff changeset
733 ## Linear interpretation with vector XI doesn't lead to matrix output
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
734 %!assert <*49506> (interp2 ([2 3], [2 3 4], [1 2; 3 4; 5 6], [2 3], 3, "linear"), [3 4])
22727
125391edc71b interp2.m: Re-orient vector/vector indexing in "linear" to fix output sizie (bug #49506).
Rik <rik@octave.org>
parents: 22489
diff changeset
735
13149
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
736 %!shared z, zout, tol
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
737 %! z = [1 3 5; 3 5 7; 5 7 9];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
738 %! 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];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
739 %! tol = 2 * eps;
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
740 %!
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
741 %!assert (interp2 (z), zout, tol)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
742 %!assert (interp2 (z, "linear"), zout, tol)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
743 %!assert (interp2 (z, "pchip"), zout, tol)
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
744 %!assert (interp2 (z, "cubic"), zout, tol)
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
745 %!assert (interp2 (z, "spline"), zout, tol)
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
746 %!assert (interp2 (z, [2 3 1], [2 2 2].', "linear"),
30330
01de0045b2e3 maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29359
diff changeset
747 %! repmat ([5, 7, 3], [3, 1]), tol)
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
748 %!assert (interp2 (z, [2 3 1], [2 2 2].', "pchip"),
30330
01de0045b2e3 maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29359
diff changeset
749 %! repmat ([5, 7, 3], [3, 1]), tol)
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
750 %!assert (interp2 (z, [2 3 1], [2 2 2].', "cubic"),
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
751 %! repmat ([5, 7, 3], [3, 1]), tol)
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
752 %!assert (interp2 (z, [2 3 1], [2 2 2].', "spline"),
30330
01de0045b2e3 maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29359
diff changeset
753 %! repmat ([5, 7, 3], [3, 1]), tol)
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
754 %!assert (interp2 (z, [2 3 1], [2 2 2], "linear"), [5 7 3], tol)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
755 %!assert (interp2 (z, [2 3 1], [2 2 2], "pchip"), [5 7 3], tol)
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
756 %!assert (interp2 (z, [2 3 1], [2 2 2], "cubic"), [5 7 3], tol)
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
757 %!assert (interp2 (z, [2 3 1], [2 2 2], "spline"), [5 7 3], tol)
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
758 %!assert (interp2 (z, [3; 3; 3], [2; 3; 1], "linear"), [7; 9; 5], tol)
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
759 %!assert (interp2 (z, [3; 3; 3], [2; 3; 1], "pchip"), [7; 9; 5], tol)
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
760 %!assert (interp2 (z, [3; 3; 3], [2; 3; 1], "cubic"), [7; 9; 5], tol)
30802
836104321759 * interp2.m: Use 'test <BUG-ID>' instead of 'xtest'.
John W. Eaton <jwe@octave.org>
parents: 30718
diff changeset
761 %!test <62132>
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
762 %! # FIXME: single column yields single row with spline interpolation (numbers are correct)
31551
fd29c7a50a78 maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents: 31253
diff changeset
763 %! assert (interp2 (z, [3; 3; 3], [2; 3; 1], "spline"), [7; 9; 5], tol);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
764
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19795
diff changeset
765 ## Test input validation
21173
5ecdcc6320d9 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 19833
diff changeset
766 %!error interp2 (1, 1, 1, 1, 1, 2) # only 5 numeric inputs
5ecdcc6320d9 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 19833
diff changeset
767 %!error interp2 (1, 1, 1, 1, 1, 2, 2) # only 5 numeric inputs
18664
900b524d9072 interp2: Verify Z matrix is 2-D (bug #41267).
Rik <rik@octave.org>
parents: 18641
diff changeset
768 %!error <Z must be a 2-D matrix> interp2 ({1})
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
769 %!error <Z must be a 2-D matrix> interp2 (1,1,1)
18664
900b524d9072 interp2: Verify Z matrix is 2-D (bug #41267).
Rik <rik@octave.org>
parents: 18641
diff changeset
770 %!error <Z must be a 2-D matrix> interp2 (ones (2,2,2))
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
771 %!error <N must be an integer .= 0> interp2 (ones (2), ones (2))
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
772 %!error <N must be an integer .= 0> interp2 (ones (2), -1)
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
773 %!error <N must be an integer .= 0> interp2 (ones (2), 1.5)
18641
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
774 %!warning <ignoring unsupported '\*' flag> interp2 (rand (3,3), 1, "*linear");
30714
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
775 %!error <EXTRAP must be a numeric scalar> interp2 (1, 1, 1, 1, 1, "linear", {1})
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
776 %!error <EXTRAP must be a numeric scalar> interp2 (1, 1, 1, 1, 1, "linear", ones (2,2))
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
777 %!error <EXTRAP must be a numeric scalar> interp2 (1, 1, 1, 1, 1, "linear", "abc")
98484425bd1b interp2: Implement bicubic interpolation (bug #61754).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30689
diff changeset
778 %!error <EXTRAP must be a numeric scalar> interp2 (1, 1, 1, 1, 1, "linear", "extrap")
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
779 %!error <X, Y must be numeric matrices> interp2 ({1}, 1, ones (2), 1, 1)
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
780 %!error <X, Y must be numeric matrices> interp2 (1, {1}, ones (2), 1, 1)
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
781 %!error <XI, YI must be numeric> interp2 (1, 1, ones (2), {1}, 1)
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
782 %!error <XI, YI must be numeric> interp2 (1, 1, ones (2), 1, {1})
28912
0de38a6ef693 maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents: 27923
diff changeset
783 %!error <X and Y must be matrices of equal size> interp2 (ones (2,2), 1, ones (2), 1, 1)
0de38a6ef693 maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents: 27923
diff changeset
784 %!error <X and Y must be matrices of equal size> interp2 (ones (2,2), ones (2,3), ones (2), 1, 1)
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
785 %!error <X and Y size must match the dimensions of Z> interp2 (1:3, 1:3, ones (3,2), 1, 1)
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
786 %!error <X and Y size must match the dimensions of Z> interp2 (1:2, 1:2, ones (3,2), 1, 1)
18641
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
787 %!error <X must be strictly monotonic> interp2 ([1 0 2], 1:3, ones (3,3), 1, 1)
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
788 %!error <Y must be strictly monotonic> interp2 (1:3, [1 0 2], ones (3,3), 1, 1)
30718
95ee9b9605cc maint: Tweaks to cset 98484425bd1b (interp2) for Octave coding conventions.
Rik <rik@octave.org>
parents: 30714
diff changeset
789 %!warning <cubic requires at least 3 points in each dimension.> interp2 (eye(2), 1.5, 1.5, "cubic");
28912
0de38a6ef693 maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents: 27923
diff changeset
790 %!error <XI and YI must be matrices of equal size> interp2 (1:2, 1:2, ones (2), ones (2,2), 1)
0de38a6ef693 maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents: 27923
diff changeset
791 %!error <XI and YI must be matrices of equal size> interp2 (1:2, 1:2, ones (2), 1, ones (2,2))
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
792 %!error <XI, YI must have uniform spacing> interp2 (1:2, 1:2, ones (2), [1 2 4], [1 2 3], "spline")
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
793 %!error <XI, YI must have uniform spacing> interp2 (1:2, 1:2, ones (2), [1 2 3], [1 2 4], "spline")
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19597
diff changeset
794 %!error interp2 (1, 1, 1, 1, 1, "foobar")