annotate scripts/general/interpn.m @ 31158:8f3885b4d7ae stable

test: Set random state and increase tolerance for interpn.m test (bug #62817)
author Arun Giridhar <arungiridhar@gmail.com>
date Thu, 28 Jul 2022 19:22:56 -0400
parents 92cda11fb171
children 731b6a5c7c4c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30330
diff changeset
3 ## Copyright (C) 2007-2022 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27853
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/>.
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
7 ##
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
8 ## This file is part of Octave.
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
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: 22323
diff changeset
13 ## (at your option) any later version.
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
14 ##
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
19 ##
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
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 ########################################################################
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
25
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20735
diff changeset
27 ## @deftypefn {} {@var{vi} =} interpn (@var{x1}, @var{x2}, @dots{}, @var{v}, @var{y1}, @var{y2}, @dots{})
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{vi} =} interpn (@var{v}, @var{y1}, @var{y2}, @dots{})
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{vi} =} interpn (@var{v}, @var{m})
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{vi} =} interpn (@var{v})
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{vi} =} interpn (@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{vi} =} interpn (@dots{}, @var{method}, @var{extrapval})
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
33 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
34 ## Perform @var{n}-dimensional interpolation, where @var{n} is at least two.
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
35 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
36 ## Each element of the @var{n}-dimensional array @var{v} represents a value
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
37 ## at a location given by the parameters @var{x1}, @var{x2}, @dots{}, @var{xn}.
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
38 ## The parameters @var{x1}, @var{x2}, @dots{}, @var{xn} are either
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
39 ## @var{n}-dimensional arrays of the same size as the array @var{v} in
29284
067b663529bb interpn.m: Fix check for scattered point coordinates (bug #59856).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
40 ## the @qcode{"ndgrid"} format or vectors.
067b663529bb interpn.m: Fix check for scattered point coordinates (bug #59856).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
41 ##
067b663529bb interpn.m: Fix check for scattered point coordinates (bug #59856).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
42 ## The parameters @var{y1}, @var{y2}, @dots{}, @var{yn} represent the points at
067b663529bb interpn.m: Fix check for scattered point coordinates (bug #59856).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
43 ## which the array @var{vi} is interpolated. They can be vectors of the same
067b663529bb interpn.m: Fix check for scattered point coordinates (bug #59856).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
44 ## length and orientation in which case they are interpreted as coordinates of
067b663529bb interpn.m: Fix check for scattered point coordinates (bug #59856).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
45 ## scattered points. If they are vectors of differing orientation or length,
067b663529bb interpn.m: Fix check for scattered point coordinates (bug #59856).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
46 ## they are used to form a grid in @qcode{"ndgrid"} format. They can also be
067b663529bb interpn.m: Fix check for scattered point coordinates (bug #59856).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
47 ## @var{n}-dimensional arrays of equal size.
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
48 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
49 ## If @var{x1}, @dots{}, @var{xn} are omitted, they are assumed to be
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
50 ## @code{x1 = 1 : size (@var{v}, 1)}, etc. If @var{m} is specified, then
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
51 ## the interpolation adds a point half way between each of the interpolation
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
52 ## points. This process is performed @var{m} times. If only @var{v} is
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
53 ## specified, then @var{m} is assumed to be @code{1}.
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
54 ##
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
55 ## The interpolation @var{method} is one of:
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
56 ##
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
57 ## @table @asis
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16891
diff changeset
58 ## @item @qcode{"nearest"}
9070
e9dc2ed2ec0f Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
59 ## Return the nearest neighbor.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10819
diff changeset
60 ##
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
61 ## @item @qcode{"linear"} (default)
9070
e9dc2ed2ec0f Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
62 ## Linear interpolation from nearest neighbors.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10819
diff changeset
63 ##
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
64 ## @item @qcode{"pchip"}
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
65 ## Piecewise cubic Hermite interpolating polynomial---shape-preserving
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
66 ## interpolation with smooth first derivative (not implemented yet).
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
67 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16891
diff changeset
68 ## @item @qcode{"cubic"}
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
69 ## Cubic interpolation (same as @qcode{"pchip"} [not implemented yet]).
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10819
diff changeset
70 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16891
diff changeset
71 ## @item @qcode{"spline"}
12175
2090995ca588 Correct en-dash,em-dash instances in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
72 ## Cubic spline interpolation---smooth first and second derivatives
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
73 ## throughout the curve.
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
74 ## @end table
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
75 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16891
diff changeset
76 ## The default method is @qcode{"linear"}.
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
77 ##
19795
ca7599ae464d doc: Grammarcheck documentation ahead of 4.0 release.
Rik <rik@octave.org>
parents: 19697
diff changeset
78 ## @var{extrapval} is a scalar number. It replaces values beyond the endpoints
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
79 ## with @var{extrapval}. Note that if @var{extrapval} is used, @var{method}
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
80 ## must be specified as well. If @var{extrapval} is omitted and the
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
81 ## @var{method} is @qcode{"spline"}, then the extrapolated values of the
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
82 ## @qcode{"spline"} are used. Otherwise the default @var{extrapval} value for
29288
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
83 ## any other @var{method} is @code{NA}.
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
84 ## @seealso{interp1, interp2, interp3, spline, ndgrid}
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
85 ## @end deftypefn
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
86
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
87 function vi = interpn (varargin)
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
88
29288
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
89 if (nargin < 1 || ! isnumeric (varargin{1}))
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
90 print_usage ();
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
91 endif
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
92
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
93 method = "linear";
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
94 extrapval = [];
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
95 nargs = nargin;
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
96
29288
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
97 ## Find and validate EXTRAPVAL and/or METHOD inputs
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
98 if (nargs > 1 && ischar (varargin{end-1}))
7208
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7016
diff changeset
99 if (! isnumeric (varargin{end}) || ! isscalar (varargin{end}))
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
100 error ("interpn: EXTRAPVAL must be a numeric scalar");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
101 endif
8116
6c69f5cda32b For for extrapval in interpn
Kris Thielemans
parents: 7671
diff changeset
102 extrapval = varargin{end};
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
103 method = varargin{end-1};
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
104 nargs -= 2;
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
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: 18587
diff changeset
106 method = varargin{end};
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 20158
diff changeset
107 nargs -= 1;
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
108 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
109
18587
5cf9a02732b6 Issue warning when '*' flag used with interp2,3,n.m (bug #41459).
Rik <rik@octave.org>
parents: 17744
diff changeset
110 if (method(1) == "*")
5cf9a02732b6 Issue warning when '*' flag used with interp2,3,n.m (bug #41459).
Rik <rik@octave.org>
parents: 17744
diff changeset
111 warning ("interpn: ignoring unsupported '*' flag to METHOD");
5cf9a02732b6 Issue warning when '*' flag used with interp2,3,n.m (bug #41459).
Rik <rik@octave.org>
parents: 17744
diff changeset
112 method(1) = [];
5cf9a02732b6 Issue warning when '*' flag used with interp2,3,n.m (bug #41459).
Rik <rik@octave.org>
parents: 17744
diff changeset
113 endif
29288
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
114 method = validatestring (method,
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
115 {"nearest", "linear", "pchip", "cubic", "spline"},
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
116 "interpn");
18587
5cf9a02732b6 Issue warning when '*' flag used with interp2,3,n.m (bug #41459).
Rik <rik@octave.org>
parents: 17744
diff changeset
117
29288
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
118 if (nargs <= 2)
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
119 ## Calling form interpn (V, ...)
7208
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7016
diff changeset
120 v = varargin{1};
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
121 m = 1;
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
122 if (nargs == 2)
29288
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
123 m = varargin{2};
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
124 if (! (isnumeric (m) && isscalar (m) && m == fix (m)))
13151
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
125 print_usage ();
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
126 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
127 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
128 sz = size (v);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
129 nd = ndims (v);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
130 x = cell (1, nd);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
131 y = cell (1, nd);
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
132 for i = 1 : nd
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
133 x{i} = 1 : sz(i);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
134 y{i} = 1 : (1 / (2 ^ m)) : sz(i);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
135 endfor
13151
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
136 y{1} = y{1}.';
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
137 [y{:}] = ndgrid (y{:});
7208
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7016
diff changeset
138 elseif (! isvector (varargin{1}) && nargs == (ndims (varargin{1}) + 1))
29288
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
139 ## Calling form interpn (V, Y1, Y2, ...)
7208
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7016
diff changeset
140 v = varargin{1};
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
141 sz = size (v);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
142 nd = ndims (v);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
143 x = cell (1, nd);
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
144 y = varargin(2 : nargs);
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
145 for i = 1 : nd
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
146 x{i} = 1 : sz(i);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
147 endfor
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
148 elseif (rem (nargs, 2) == 1
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
149 && nargs == (2 * ndims (varargin{ceil (nargs / 2)})) + 1)
29288
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
150 ## Calling form interpn (X1, X2, ..., V, Y1, Y2, ...)
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
151 nv = ceil (nargs / 2);
7208
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7016
diff changeset
152 v = varargin{nv};
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
153 sz = size (v);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
154 nd = ndims (v);
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
155 x = varargin(1 : (nv - 1));
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
156 y = varargin((nv + 1) : nargs);
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
157 else
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
158 error ("interpn: wrong number or incorrectly formatted input arguments");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
159 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
160
12931
cefd568ea073 Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents: 12175
diff changeset
161 if (any (! cellfun ("isvector", x)))
29288
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
162 for i = 1 : nd
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
163 if (! size_equal (x{i}, v))
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
164 error ("interpn: incorrect dimensions for input X%d", i);
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
165 endif
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
166 idx(1 : nd) = {1};
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
167 idx(i) = ":";
6721
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
168 x{i} = x{i}(idx{:})(:);
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
169 endfor
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
170 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
171
12931
cefd568ea073 Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents: 12175
diff changeset
172 all_vectors = all (cellfun ("isvector", y));
29286
4cb0fc7ecd4b interpn.m: Use size_equal for 10X speedup in cset 067b663529bb (bug #59856).
Rik <rik@octave.org>
parents: 29284
diff changeset
173 same_size = size_equal (y{:});
29284
067b663529bb interpn.m: Fix check for scattered point coordinates (bug #59856).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
174 if (all_vectors && ! same_size)
29288
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
175 [y{:}] = ndgrid (y{:});
10819
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
176 endif
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
177
30684
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
178 if (! strcmp (method, "spline") && isempty (extrapval))
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
179 if (iscomplex (v))
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
180 extrapval = NA + 1i*NA;
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
181 else
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
182 extrapval = NA;
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
183 endif
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
184 endif
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
185
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
186 if (strcmp (method, "linear"))
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
187 vi = __lin_interpn__ (x{:}, v, y{:});
30684
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
188 if (iscomplex (v))
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
189 ## __lin_interpn__ ignores imaginary part. Do it again for imag part.
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
190 ## FIXME: Adapt __lin_interpn__ to correctly handle complex input.
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
191 vi += 1i * __lin_interpn__ (x{:}, imag (v), y{:});
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
192 endif
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
193 vi(isna (vi)) = extrapval;
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
194 elseif (strcmp (method, "nearest"))
29288
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
195 ## FIXME: This seems overly complicated. Is there a way to simplify
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
196 ## all the code after the call to lookup (which should be fast)?
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
197 ## Could Qhull be used for quick nearest neighbor calculation?
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
198 yshape = size (y{1});
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
199 yidx = cell (1, nd);
29288
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
200 ## Find rough nearest index using lookup function [O(log2 (N)].
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
201 for i = 1 : nd
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
202 y{i} = y{i}(:);
7671
4fbaba9abec1 implement compiled binary lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 7561
diff changeset
203 yidx{i} = lookup (x{i}, y{i}, "lr");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
204 endfor
29288
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
205 ## Single comparison to next largest index to see which is closer.
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
206 idx = cell (1,nd);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
207 for i = 1 : nd
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19795
diff changeset
208 idx{i} = yidx{i} ...
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19795
diff changeset
209 + (y{i} - x{i}(yidx{i})(:) >= x{i}(yidx{i} + 1)(:) - y{i});
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
210 endfor
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
211 vi = v(sub2ind (sz, idx{:}));
29288
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
212 ## Apply EXTRAPVAL to points outside original volume.
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
213 idx = false (prod (yshape), 1);
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
214 for i = 1 : nd
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
215 idx |= y{i} < min (x{i}(:)) | y{i} > max (x{i}(:));
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
216 endfor
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
217 vi(idx) = extrapval;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
218 vi = reshape (vi, yshape);
6721
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
219 elseif (strcmp (method, "spline"))
12931
cefd568ea073 Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents: 12175
diff changeset
220 if (any (! cellfun ("isvector", y)))
29288
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
221 ysz = size (y{1});
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
222 for i = 1 : nd
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
223 if (any (size (y{i}) != ysz))
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
224 error ("interpn: incorrect dimensions for input Y%d", i);
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
225 endif
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
226 idx(1 : nd) = {1};
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
227 idx(i) = ":";
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
228 y{i} = y{i}(idx{:});
7423
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
229 endfor
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
230 endif
7421
1c7b3e1fda19 [project @ 2008-01-25 21:00:42 by dbateman]
dbateman
parents: 7208
diff changeset
231
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
232 vi = __splinen__ (x, v, y, extrapval, "interpn");
7421
1c7b3e1fda19 [project @ 2008-01-25 21:00:42 by dbateman]
dbateman
parents: 7208
diff changeset
233
7423
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
234 if (size_equal (y{:}))
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
235 ly = length (y{1});
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
236 idx = cell (1, ly);
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
237 q = cell (1, nd);
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
238 for i = 1 : ly
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
239 q(:) = i;
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
240 idx{i} = q;
7423
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
241 endfor
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
242 vi = vi(cellfun (@(x) sub2ind (size (vi), x{:}), idx));
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
243 vi = reshape (vi, size (y{1}));
7423
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
244 endif
29288
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
245 elseif (strcmp (method, "pchip"))
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
246 error ("interpn: pchip interpolation not yet implemented");
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
247 elseif (strcmp (method, "cubic"))
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
248 error ("interpn: cubic interpolation not yet implemented");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
249 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
250
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
251 endfunction
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
252
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
253
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
254 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
255 %! clf;
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
256 %! 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
257 %! 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
258 %! 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
259 %! 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
260 %! 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
261 %! mesh (xi, yi, interpn (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
262 %! [x,y] = meshgrid (x,y);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
263 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off;
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
264
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
265 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
266 %! clf;
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
267 %! 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
268 %! 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
269 %! 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
270 %! 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
271 %! 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
272 %! mesh (xi, yi, interpn (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
273 %! [x,y] = meshgrid (x,y);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
274 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off;
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
275
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
276 %!#demo # FIXME: Uncomment when support for "cubic" has been added
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
277 %! clf;
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
278 %! 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
279 %! 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
280 %! 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
281 %! 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
282 %! 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
283 %! mesh (xi, yi, interpn (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
284 %! [x,y] = meshgrid (x,y);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
285 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off;
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
286
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
287 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
288 %! clf;
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
289 %! 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
290 %! 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
291 %! 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
292 %! 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
293 %! 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
294 %! mesh (xi, yi, interpn (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
295 %! [x,y] = meshgrid (x,y);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
296 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off;
6721
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
297
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
298 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
299 %! clf;
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
300 %! colormap ("default");
6721
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
301 %! x = y = z = -1:1;
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
302 %! f = @(x,y,z) x.^2 - y - z.^2;
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
303 %! [xx, yy, zz] = meshgrid (x, y, z);
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
304 %! v = f (xx,yy,zz);
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
305 %! xi = yi = zi = -1:0.1:1;
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
306 %! [xxi, yyi, zzi] = ndgrid (xi, yi, zi);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
307 %! vi = interpn (x, y, z, v, xxi, yyi, zzi, "spline");
6721
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
308 %! mesh (yi, zi, squeeze (vi(1,:,:)));
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
309
7421
1c7b3e1fda19 [project @ 2008-01-25 21:00:42 by dbateman]
dbateman
parents: 7208
diff changeset
310 %!test
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
311 %! [x,y,z] = ndgrid (0:2);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
312 %! f = x + y + z;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
313 %! assert (interpn (x,y,z,f,[.5 1.5],[.5 1.5],[.5 1.5]), [1.5, 4.5]);
30330
01de0045b2e3 maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29359
diff changeset
314 %! assert (interpn (x,y,z,f,[.51 1.51],[.51 1.51],[.51 1.51],"nearest"),
01de0045b2e3 maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29359
diff changeset
315 %! [3, 6]);
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
316 %! assert (interpn (x,y,z,f,[.5 1.5],[.5 1.5],[.5 1.5],"spline"), [1.5, 4.5]);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
317 %! assert (interpn (x,y,z,f,x,y,z), f);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
318 %! assert (interpn (x,y,z,f,x,y,z,"nearest"), f);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
319 %! assert (interpn (x,y,z,f,x,y,z,"spline"), f);
7561
a938cd7869b2 __lin_interpn__.cc: handle decreasing coordinate values
Alexander Barth
parents: 7424
diff changeset
320
a938cd7869b2 __lin_interpn__.cc: handle decreasing coordinate values
Alexander Barth
parents: 7424
diff changeset
321 %!test
10819
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
322 %! [x, y, z] = ndgrid (0:2, 1:4, 2:6);
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
323 %! f = x + y + z;
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
324 %! xi = [0.5 1.0 1.5]; yi = [1.5 2.0 2.5 3.5]; zi = [2.5 3.5 4.0 5.0 5.5];
10819
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
325 %! fi = interpn (x, y, z, f, xi, yi, zi);
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
326 %! [xi, yi, zi] = ndgrid (xi, yi, zi);
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
327 %! assert (fi, xi + yi + zi);
10819
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
328
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
329 %!test
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
330 %! xi = 0:2; yi = 1:4; zi = 2:6;
10819
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
331 %! [x, y, z] = ndgrid (xi, yi, zi);
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
332 %! f = x + y + z;
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
333 %! fi = interpn (x, y, z, f, xi, yi, zi, "nearest");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
334 %! assert (fi, x + y + z);
10819
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
335
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
336 %!test
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
337 %! [x,y,z] = ndgrid (0:2);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
338 %! f = x.^2 + y.^2 + z.^2;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
339 %! assert (interpn (x,y,-z,f,1.5,1.5,-1.5), 7.5);
10427
62bb59f927b1 scripts/general/interp2.m, scripts/general/interpn.m: For nearest neighbour interpolation ceil (instead of floor) at the center of the data intervals to be compatible with Matlab. Add test.
Soren Hauberg <hauberg@gmail.com>
parents: 9245
diff changeset
340
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
341 %!test # for Matlab-compatible rounding for "nearest"
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
342 %! x = meshgrid (1:4);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
343 %! assert (interpn (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: 9245
diff changeset
344
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
345 %!test
13151
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
346 %! z = zeros (3, 3, 3);
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
347 %! zout = zeros (5, 5, 5);
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
348 %! z(:,:,1) = [1 3 5; 3 5 7; 5 7 9];
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
349 %! z(:,:,2) = z(:,:,1) + 2;
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
350 %! z(:,:,3) = z(:,:,2) + 2;
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
351 %! for n = 1:5
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
352 %! zout(:,:,n) = [1 2 3 4 5;
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
353 %! 2 3 4 5 6;
13151
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
354 %! 3 4 5 6 7;
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
355 %! 4 5 6 7 8;
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
356 %! 5 6 7 8 9] + (n-1);
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
357 %! endfor
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
358 %! tol = 10*eps;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
359 %! assert (interpn (z), zout, tol);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
360 %! assert (interpn (z, "linear"), zout, tol);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
361 %! assert (interpn (z, "spline"), zout, tol);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
362
30684
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
363 ## Test that interpolating a complex matrix is equivalent to interpolating its
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
364 ## real and imaginary parts separately.
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
365 %!test <*61907>
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
366 %! yi = [0.5, 1.5]';
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
367 %! xi = [2.5, 3.5];
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
368 %! zi = [2.25, 4.75];
31158
8f3885b4d7ae test: Set random state and increase tolerance for interpn.m test (bug #62817)
Arun Giridhar <arungiridhar@gmail.com>
parents: 30684
diff changeset
369 %! rand ("state", 1340640850);
30684
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
370 %! v = rand (4, 3, 5) + 1i * rand (4, 3, 5);
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
371 %! for method = {"nearest", "linear", "spline"}
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
372 %! vi_complex = interpn (v, yi, xi, zi, method{1});
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
373 %! vi_real = interpn (real (v), yi, xi, zi, method{1});
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
374 %! vi_imag = interpn (imag (v), yi, xi, zi, method{1});
31158
8f3885b4d7ae test: Set random state and increase tolerance for interpn.m test (bug #62817)
Arun Giridhar <arungiridhar@gmail.com>
parents: 30684
diff changeset
375 %! assert (real (vi_complex), vi_real, 2*eps)
8f3885b4d7ae test: Set random state and increase tolerance for interpn.m test (bug #62817)
Arun Giridhar <arungiridhar@gmail.com>
parents: 30684
diff changeset
376 %! assert (imag (vi_complex), vi_imag, 2*eps)
30684
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
377 %! endfor
92cda11fb171 interpn: Fix issues with complex input (bug #61907).
Christof Kaufmann <christofkaufmann.dev@gmail.com>
parents: 30564
diff changeset
378
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19795
diff changeset
379 ## Test input validation
29288
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
380 %!error <Invalid call> interpn ()
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
381 %!error <Invalid call> interpn ("foobar")
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
382 %!error <EXTRAPVAL must be a numeric scalar> interpn (1, "linear", {1})
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
383 %!error <EXTRAPVAL must be a numeric scalar> interpn (1, "linear", [1, 2])
18587
5cf9a02732b6 Issue warning when '*' flag used with interp2,3,n.m (bug #41459).
Rik <rik@octave.org>
parents: 17744
diff changeset
384 %!warning <ignoring unsupported '\*' flag> interpn (rand (3,3), 1, "*linear");
29288
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
385 %!error <'foobar' does not match any of> interpn (1, "foobar")
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
386 %!error <wrong number or incorrectly formatted input arguments>
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
387 %! interpn (1, 2, 3, 4);
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
388 %!error <incorrect dimensions for input X1>
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
389 %! interpn ([1,2], ones (2,2), magic (3), [1,2], [1,2])
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
390 %!error <incorrect dimensions for input X2>
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
391 %! interpn (ones (3,3), ones (2,2), magic (3), [1,2], [1,2])
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
392 %!error <incorrect dimensions for input Y2>
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
393 %! interpn ([1,2], [1,2], magic (3), [1,2], ones (2,2), "spline")
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
394 %!error <pchip interpolation not yet implemented> interpn ([1,2], "pchip")
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
395 %!error <cubic interpolation not yet implemented> interpn ([1,2], "cubic")
512591ccb174 interpn.m: Overhaul function.
Rik <rik@octave.org>
parents: 29286
diff changeset
396