Mercurial > octave
annotate scripts/general/interp2.m @ 30661:27566803b3b1 stable
interp2: Fix issues with complex input (bug #61863).
* scripts/general/interp2.m: Fix interpolation of imaginary part of complex
numbers for "pchip". Fix value for extrapolation of complex values. Add BIST.
* doc/interpreter/contributors.in: Add name to list of contributors.
author | Christof Kaufmann <christofkaufmann.dev@gmail.com> |
---|---|
date | Sat, 22 Jan 2022 11:25:04 +0100 |
parents | 796f54d4ddbf |
children | 9b8c74d85fa7 |
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 | 7 ## |
8 ## This file is part of Octave. | |
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 | 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 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
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 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 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 | 25 |
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 | 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 | 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 | 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 | 59 ## |
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 | 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 | 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"} |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
72 ## Cubic interpolation (same as @qcode{"pchip"}). |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
73 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
74 ## @item @qcode{"spline"} |
12175
2090995ca588
Correct en-dash,em-dash instances in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
11589
diff
changeset
|
75 ## Cubic spline interpolation---smooth first and second derivatives |
6702 | 76 ## throughout the curve. |
5837 | 77 ## @end table |
78 ## | |
19795
ca7599ae464d
doc: Grammarcheck documentation ahead of 4.0 release.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
79 ## @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
|
80 ## 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
|
81 ## 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
|
82 ## @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
|
83 ## 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
|
84 ## is @qcode{"NA"}. |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
85 ## @seealso{interp1, interp3, interpn, meshgrid} |
5837 | 86 ## @end deftypefn |
87 | |
19658
5a59c0e1203d
Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19597
diff
changeset
|
88 function ZI = interp2 (varargin) |
5837 | 89 |
19658
5a59c0e1203d
Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19597
diff
changeset
|
90 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
|
91 nargs = nargin; |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
92 |
5838 | 93 Z = X = Y = XI = YI = n = []; |
5837 | 94 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
|
95 extrap = []; |
5837 | 96 |
19658
5a59c0e1203d
Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19597
diff
changeset
|
97 ## 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
|
98 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
|
99 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
|
100 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
|
101 endif |
5a59c0e1203d
Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19597
diff
changeset
|
102 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
|
103 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
|
104 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
|
105 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
|
106 method = varargin{end}; |
20735
418ae0cb752f
Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
107 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
|
108 endif |
5a59c0e1203d
Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19597
diff
changeset
|
109 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
|
110 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
|
111 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
|
112 endif |
5a59c0e1203d
Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19597
diff
changeset
|
113 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
|
114 {"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
|
115 |
5a59c0e1203d
Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19597
diff
changeset
|
116 ## 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
|
117 switch (nargs) |
5838 | 118 case 1 |
119 Z = varargin{1}; | |
13149
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
120 n = 1; |
5838 | 121 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
|
122 [Z, n] = deal (varargin{1:nargs}); |
5838 | 123 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
|
124 [Z, XI, YI] = deal (varargin{1:nargs}); |
5838 | 125 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
|
126 [X, Y, Z, XI, YI] = deal (varargin{1:nargs}); |
5838 | 127 otherwise |
128 print_usage (); | |
5837 | 129 endswitch |
130 | |
18641
4792a115c735
interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents:
18606
diff
changeset
|
131 ## 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
|
132 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
|
133 error ("interp2: Z must be a 2-D matrix"); |
5837 | 134 endif |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
135 if (! isempty (n) && ! (isscalar (n) && n >= 0 && n == fix (n))) |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
136 error ("interp2: N must be an integer >= 0"); |
5837 | 137 endif |
138 | |
5838 | 139 ## Define X, Y, XI, YI if needed |
5837 | 140 [zr, zc] = size (Z); |
5838 | 141 if (isempty (X)) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
142 X = 1:zc; |
5838 | 143 Y = 1:zr; |
5837 | 144 endif |
5838 | 145 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
|
146 error ("interp2: X, Y must be numeric matrices"); |
5837 | 147 endif |
5838 | 148 if (! isempty (n)) |
13149
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
149 ## 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
|
150 p = 2^n; |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
151 XI = (p:p*zc)/p; |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
152 YI = (p:p*zr)'/p; |
5837 | 153 endif |
5838 | 154 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
|
155 error ("interp2: XI, YI must be numeric"); |
5837 | 156 endif |
157 | |
18641
4792a115c735
interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents:
18606
diff
changeset
|
158 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
|
159 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
|
160 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
|
161 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
|
162 else |
4792a115c735
interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents:
18606
diff
changeset
|
163 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
|
164 endif |
4792a115c735
interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents:
18606
diff
changeset
|
165 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
|
166 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
|
167 endif |
4792a115c735
interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents:
18606
diff
changeset
|
168 dx = diff (X); |
4792a115c735
interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents:
18606
diff
changeset
|
169 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
|
170 X = flipud (X); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19596
diff
changeset
|
171 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
|
172 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
|
173 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
|
174 endif |
4792a115c735
interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents:
18606
diff
changeset
|
175 dy = diff (Y); |
4792a115c735
interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents:
18606
diff
changeset
|
176 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
|
177 Y = flipud (Y); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19596
diff
changeset
|
178 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
|
179 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
|
180 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
|
181 endif |
6702 | 182 |
18641
4792a115c735
interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents:
18606
diff
changeset
|
183 if (any (strcmp (method, {"nearest", "linear", "pchip", "cubic"}))) |
6702 | 184 |
185 ## If Xi and Yi are vectors of different orientation build a grid | |
22729 | 186 if ((isrow (XI) && iscolumn (YI)) || (iscolumn (XI) && isrow (YI))) |
6702 | 187 [XI, YI] = meshgrid (XI, YI); |
188 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
|
189 error ("interp2: XI and YI must be matrices of equal size"); |
6702 | 190 endif |
5837 | 191 |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
192 ## if XI, YI are vectors, X and Y should share their orientation. |
22729 | 193 if (isrow (XI)) |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
194 if (rows (X) != 1) |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
195 X = X.'; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
196 endif |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
197 if (rows (Y) != 1) |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
198 Y = Y.'; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
199 endif |
22729 | 200 elseif (iscolumn (XI)) |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
201 if (columns (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 (columns (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 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
207 endif |
6702 | 208 |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
209 xidx = lookup (X, XI, "lr"); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
210 yidx = lookup (Y, YI, "lr"); |
5837 | 211 |
6702 | 212 if (strcmp (method, "linear")) |
213 ## each quad satisfies the equation z(x,y)=a+b*x+c*y+d*xy | |
214 ## | |
215 ## a-b | |
216 ## | | | |
217 ## c-d | |
218 a = Z(1:(zr - 1), 1:(zc - 1)); | |
219 b = Z(1:(zr - 1), 2:zc) - a; | |
220 c = Z(2:zr, 1:(zc - 1)) - a; | |
221 d = Z(2:zr, 2:zc) - a - b - c; | |
5837 | 222 |
6702 | 223 ## scale XI, YI values to a 1-spaced grid |
10326
ade59ae10e80
slight optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
10320
diff
changeset
|
224 Xsc = (XI - X(xidx)) ./ (diff (X)(xidx)); |
ade59ae10e80
slight optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
10320
diff
changeset
|
225 Ysc = (YI - Y(yidx)) ./ (diff (Y)(yidx)); |
6702 | 226 |
10328
2210d3070543
further memory optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
10326
diff
changeset
|
227 ## Get 2D index. |
2210d3070543
further memory optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
10326
diff
changeset
|
228 idx = sub2ind (size (a), yidx, xidx); |
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
|
229 ## Dispose of the 1D indices at this point to save memory. |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
230 clear xidx yidx; |
10328
2210d3070543
further memory optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
10326
diff
changeset
|
231 |
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
|
232 ## 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
|
233 ## 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
|
234 ## 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
|
235 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
|
236 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
|
237 + 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
|
238 + 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
|
239 + forient (d(idx)) .* Xsc.*Ysc; |
5837 | 240 |
6702 | 241 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
|
242 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
|
243 jj = (YI - Y(yidx) >= Y(yidx + 1) - YI); |
6702 | 244 idx = sub2ind (size (Z), yidx+jj, xidx+ii); |
245 ZI = Z(idx); | |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
246 |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
247 elseif (strcmp (method, "pchip") || strcmp (method, "cubic")) |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
248 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
249 if (length (X) < 2 || length (Y) < 2) |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
250 error ("interp2: %s requires at least 2 points in each dimension", |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
251 method); |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
252 endif |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
253 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
254 ## first order derivatives |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
255 DX = __pchip_deriv__ (X, Z, 2); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
256 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
|
257 ## Compute mixed derivatives row-wise and column-wise. Use the average. |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
258 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
|
259 |
30661
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
260 if (iscomplex (Z)) |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
261 ## __pchip_deriv__ works only on real part. Do it again for imag part. |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
262 ## FIXME: Adapt __pchip_deriv__ to correctly handle complex input. |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
263 |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
264 ## first order derivatives |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
265 DX += 1i * __pchip_deriv__ (X, imag (Z), 2); |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
266 DY += 1i * __pchip_deriv__ (Y, imag (Z), 1); |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
267 ## Compute mixed derivatives row-wise and column-wise. Use the average. |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
268 DXY += 1i * (__pchip_deriv__ (X, imag (DY), 2) |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
269 + __pchip_deriv__ (Y, imag (DX), 1))/2; |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
270 endif |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
271 |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
272 ## do the bicubic interpolation |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
273 hx = diff (X); hx = hx(xidx); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
274 hy = diff (Y); hy = hy(yidx); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
275 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
276 tx = (XI - X(xidx)) ./ hx; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
277 ty = (YI - Y(yidx)) ./ hy; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
278 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
279 ## construct the cubic hermite base functions in x, y |
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 ## formulas: |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
282 ## 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
|
283 ## 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
|
284 ## b{1,2} = (-2*t.^3 + 3*t.^2 ); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
285 ## b{2,2} = h.*( t.^3 - t.^2 ); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
286 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
287 ## optimized equivalents of the above: |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
288 t1 = tx.^2; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
289 t2 = tx.*t1 - t1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
290 xb{2,2} = hx.*t2; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
291 t1 = t2 - t1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
292 xb{2,1} = hx.*(t1 + tx); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
293 t2 += t1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
294 xb{1,2} = -t2; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
295 xb{1,1} = t2 + 1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
296 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
297 t1 = ty.^2; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
298 t2 = ty.*t1 - t1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
299 yb{2,2} = hy.*t2; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
300 t1 = t2 - t1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
301 yb{2,1} = hy.*(t1 + ty); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
302 t2 += t1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
303 yb{1,2} = -t2; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
304 yb{1,1} = t2 + 1; |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
305 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
306 ZI = zeros (size (XI)); |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
307 for i = 1:2 |
10549 | 308 for j = 1:2 |
309 zidx = sub2ind (size (Z), yidx+(j-1), xidx+(i-1)); | |
310 ZI += xb{1,i} .* yb{1,j} .* Z(zidx); | |
311 ZI += xb{2,i} .* yb{1,j} .* DX(zidx); | |
312 ZI += xb{1,i} .* yb{2,j} .* DY(zidx); | |
313 ZI += xb{2,i} .* yb{2,j} .* DXY(zidx); | |
314 endfor | |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
315 endfor |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
316 |
6702 | 317 endif |
5837 | 318 |
6702 | 319 else |
5837 | 320 |
10780
6e7590d003dc
Fix bugs in interp2 (bug #29601)
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10635
diff
changeset
|
321 ## Check dimensions of XI and YI |
13149
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
322 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
|
323 XI = XI(:).'; YI = YI(:); |
6702 | 324 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
|
325 error ("interp2: XI and YI must be matrices of equal size"); |
6702 | 326 endif |
5837 | 327 |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
328 if (strcmp (method, "spline")) |
9755
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
329 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
|
330 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
|
331 else |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
332 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
|
333 endif |
6702 | 334 endif |
5837 | 335 |
19658
5a59c0e1203d
Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19597
diff
changeset
|
336 return; # spline doesn't need NA extrapolation value (MATLAB compatibility) |
5a59c0e1203d
Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19597
diff
changeset
|
337 |
5a59c0e1203d
Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19597
diff
changeset
|
338 endif |
5a59c0e1203d
Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19597
diff
changeset
|
339 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19795
diff
changeset
|
340 ## 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
|
341 if (isempty (extrap)) |
30661
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
342 if (iscomplex (Z)) |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
343 extrap = complex (NA, NA); |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
344 else |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
345 extrap = NA; |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
346 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
|
347 endif |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19795
diff
changeset
|
348 |
19658
5a59c0e1203d
Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19597
diff
changeset
|
349 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
|
350 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
|
351 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
|
352 else |
5a59c0e1203d
Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19597
diff
changeset
|
353 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
|
354 endif |
5a59c0e1203d
Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19597
diff
changeset
|
355 else |
5a59c0e1203d
Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19597
diff
changeset
|
356 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
|
357 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
|
358 else |
5a59c0e1203d
Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19597
diff
changeset
|
359 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
|
360 endif |
6702 | 361 endif |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
362 |
5837 | 363 endfunction |
364 | |
9755
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
365 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
|
366 d1 = diff (X, 1, 1); |
22729 | 367 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
|
368 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
|
369 |
4f4873f6f873
general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents:
9399
diff
changeset
|
370 |
5837 | 371 %!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
|
372 %! 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
|
373 %! 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
|
374 %! 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
|
375 %! 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
|
376 %! xi = linspace (min (x), max (x), 17); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
377 %! 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
|
378 %! 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
|
379 %! [x,y] = meshgrid (x,y); |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
380 %! hold on; plot3 (x,y,A,"b*"); hold off; |
5837 | 381 |
382 %!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
|
383 %! 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
|
384 %! 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
|
385 %! [x,y,A] = peaks (10); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
386 %! x = x(1,:)'; y = y(:,1); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
387 %! xi = linspace (min (x), max (x), 41); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
388 %! 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
|
389 %! 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
|
390 %! [x,y] = meshgrid (x,y); |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
391 %! 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
|
392 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
393 %!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
|
394 %! 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
|
395 %! 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
|
396 %! 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
|
397 %! 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
|
398 %! xi = linspace (min (x), max (x), 17); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
399 %! 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
|
400 %! 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
|
401 %! [x,y] = meshgrid (x,y); |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
402 %! hold on; plot3 (x,y,A,"b*"); hold off; |
5837 | 403 |
6702 | 404 %!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
|
405 %! 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
|
406 %! 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
|
407 %! [x,y,A] = peaks (10); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
408 %! x = x(1,:)'; y = y(:,1); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
409 %! xi = linspace (min (x), max (x), 41); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
410 %! 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
|
411 %! 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
|
412 %! [x,y] = meshgrid (x,y); |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
413 %! 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
|
414 |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
415 ## 'pchip' commented out since it is the same as 'cubic' |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
416 %!#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
|
417 %! 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
|
418 %! 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
|
419 %! 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
|
420 %! 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
|
421 %! xi = linspace (min (x), max (x), 17); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
422 %! 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
|
423 %! 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
|
424 %! [x,y] = meshgrid (x,y); |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
425 %! 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
|
426 |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
427 ## 'pchip' commented out since it is the same as 'cubic' |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
428 %!#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
|
429 %! 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
|
430 %! 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
|
431 %! [x,y,A] = peaks (10); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
432 %! x = x(1,:)'; y = y(:,1); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
433 %! xi = linspace (min (x), max (x), 41); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
434 %! 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
|
435 %! 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
|
436 %! [x,y] = meshgrid (x,y); |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
437 %! 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
|
438 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
439 %!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
|
440 %! 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
|
441 %! 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
|
442 %! 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
|
443 %! 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
|
444 %! xi = linspace (min (x), max (x), 17); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
445 %! 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
|
446 %! 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
|
447 %! [x,y] = meshgrid (x,y); |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
448 %! hold on; plot3 (x,y,A,"b*"); hold off; |
5837 | 449 |
6702 | 450 %!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
|
451 %! 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
|
452 %! 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
|
453 %! [x,y,A] = peaks (10); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
454 %! x = x(1,:)'; y = y(:,1); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
455 %! xi = linspace (min (x), max (x), 41); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
456 %! 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
|
457 %! 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
|
458 %! [x,y] = meshgrid (x,y); |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
459 %! 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
|
460 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
461 %!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
|
462 %! 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
|
463 %! 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
|
464 %! 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
|
465 %! 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
|
466 %! xi = linspace (min (x), max (x), 17); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
467 %! 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
|
468 %! 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
|
469 %! [x,y] = meshgrid (x,y); |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
470 %! hold on; plot3 (x,y,A,"b*"); hold off; |
6702 | 471 |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
8479
diff
changeset
|
472 %!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
|
473 %! 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
|
474 %! 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
|
475 %! [x,y,A] = peaks (10); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
476 %! x = x(1,:)'; y = y(:,1); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
477 %! xi = linspace (min (x), max (x), 41); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
478 %! 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
|
479 %! 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
|
480 %! [x,y] = meshgrid (x,y); |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
481 %! 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
|
482 |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
483 %!test # simple test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
484 %! x = [1,2,3]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
485 %! 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
|
486 %! [X, Y] = meshgrid (x, y); |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
487 %! 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
|
488 %! xi = [1.2,2, 1.5]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
489 %! yi = [6.2, 4.0, 5.0]'; |
5837 | 490 %! |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
491 %! expected = ... |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
492 %! [243, 245.4, 243.9; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
493 %! 65.6, 68, 66.5; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
494 %! 126.6, 129, 127.5]; |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
495 %! result = interp2 (x,y,orig, xi, yi); |
5837 | 496 %! |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
497 %! assert (result, expected, 1000*eps); |
5837 | 498 |
30661
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
499 ## 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
|
500 ## real and imaginary parts separately. |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
501 %!test <61863> |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
502 %! xi = [2.5, 3.5]; |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
503 %! yi = [0.5, 1.5]'; |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
504 %! orig = rand (2, 3) + 1i * rand (2, 3); |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
505 %! for method = {"nearest", "linear", "pchip", "spline"} |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
506 %! 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
|
507 %! 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
|
508 %! interp_imag = interp2 (imag (orig), xi, yi, method{1}); |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
509 %! assert (real (interp_complex), interp_real) |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
510 %! assert (imag (interp_complex), interp_imag) |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
511 %! endfor |
27566803b3b1
interp2: Fix issues with complex input (bug #61863).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents:
30564
diff
changeset
|
512 |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
513 %!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
|
514 %! x = [1,2,3]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
515 %! 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
|
516 %! [X, Y] = meshgrid (x, y); |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
517 %! 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
|
518 %! 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
|
519 %! expected = interp2 (x,y,orig, xi, yi); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
520 %! result = interp2 (orig, 2); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
521 %! |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
522 %! assert (result, expected, 10*eps); |
5837 | 523 |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
524 %!test # matrix slice |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
525 %! A = eye (4); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
526 %! assert (interp2 (A,[1:4],[1:4]), [1,1,1,1]); |
5837 | 527 |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
528 %!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
|
529 %! A = eye (4); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
530 %! assert (interp2 (A,[1,2;3,4],[1,3;2,4]), [1,0;0,1]); |
5837 | 531 |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
532 %!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
|
533 %! x = [1,2,3]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
534 %! 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
|
535 %! [X, Y] = meshgrid (x,y); |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
536 %! 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
|
537 %! xi = [0,4]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
538 %! yi = [3,8]'; |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
539 %! 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
|
540 %! 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
|
541 %! 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
|
542 %! 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
|
543 %! 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
|
544 %! assert (interp2 (x,y,orig, xi, yi,"spline"), [27,43;512,528]); |
5a59c0e1203d
Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19597
diff
changeset
|
545 |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
546 %!test # for values at boundaries |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
547 %! A = [1,2;3,4]; |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
548 %! x = [0,1]; |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
549 %! y = [2,3]'; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
550 %! 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
|
551 %! assert (interp2 (x,y,A,x,y,"nearest"), A); |
5837 | 552 |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
553 %!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
|
554 %! 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
|
555 %! 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
|
556 |
22489
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
21317
diff
changeset
|
557 ## 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
|
558 %!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
|
559 %!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
|
560 |
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
|
561 ## 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
|
562 %!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
|
563 |
13149
ab17591254fc
scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents:
12175
diff
changeset
|
564 %!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
|
565 %! 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
|
566 %! 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
|
567 %! tol = 2 * eps; |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18587
diff
changeset
|
568 %! |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
569 %!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
|
570 %!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
|
571 %!assert (interp2 (z, "pchip"), zout, tol) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
572 %!assert (interp2 (z, "cubic"), zout, 10 * tol) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
573 %!assert (interp2 (z, "spline"), zout, tol) |
30330
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
574 %!assert (interp2 (z, [2 3 1], [2 2 2]', "linear"), |
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
575 %! repmat ([5, 7, 3], [3, 1]), tol) |
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
576 %!assert (interp2 (z, [2 3 1], [2 2 2]', "pchip"), |
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
577 %! repmat ([5, 7, 3], [3, 1]), tol) |
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
578 %!assert (interp2 (z, [2 3 1], [2 2 2]', "cubic"), |
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
579 %! repmat ([5, 7, 3], [3, 1]), 10 * tol) |
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
580 %!assert (interp2 (z, [2 3 1], [2 2 2]', "spline"), |
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
581 %! 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
|
582 %!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
|
583 %!assert (interp2 (z, [2 3 1], [2 2 2], "pchip"), [5 7 3], tol) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
584 %!assert (interp2 (z, [2 3 1], [2 2 2], "cubic"), [5 7 3], 10 * tol) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
585 %!assert (interp2 (z, [2 3 1], [2 2 2], "spline"), [5 7 3], tol) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
586 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19795
diff
changeset
|
587 ## 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
|
588 %!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
|
589 %!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
|
590 %!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
|
591 %!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
|
592 %!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
|
593 %!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
|
594 %!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
|
595 %!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
|
596 %!warning <ignoring unsupported '\*' flag> interp2 (rand (3,3), 1, "*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
|
597 %!error <EXTRAP must be a numeric scalar> interp2 (1, 1, 1, 1, 1, 'linear', {1}) |
5a59c0e1203d
Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19597
diff
changeset
|
598 %!error <EXTRAP must be a numeric scalar> interp2 (1, 1, 1, 1, 1, 'linear', ones (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
|
599 %!error <EXTRAP must be a numeric scalar> interp2 (1, 1, 1, 1, 1, 'linear', "abc") |
5a59c0e1203d
Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19597
diff
changeset
|
600 %!error <EXTRAP must be a numeric scalar> interp2 (1, 1, 1, 1, 1, 'linear', "extrap") |
5a59c0e1203d
Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19597
diff
changeset
|
601 %!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
|
602 %!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
|
603 %!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
|
604 %!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
|
605 %!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
|
606 %!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
|
607 %!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
|
608 %!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
|
609 %!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
|
610 %!error <Y must be strictly monotonic> interp2 (1:3, [1 0 2], ones (3,3), 1, 1) |
28912
0de38a6ef693
maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
611 %!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
|
612 %!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
|
613 %!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
|
614 %!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
|
615 %!error interp2 (1, 1, 1, 1, 1, "foobar") |