annotate scripts/general/interpn.m @ 27923:b442ec6dda5c

use centralized file for copyright info for individual contributors * COPYRIGHT.md: New file. * In most other files, use "Copyright (C) YYYY-YYYY The Octave Project Developers" instead of tracking individual names in separate source files. The motivation is to reduce the effort required to update the notices each year. Until now, the Octave source files contained copyright notices that list individual contributors. I adopted these file-scope copyright notices because that is what everyone was doing 30 years ago in the days before distributed version control systems. But now, with many contributors and modern version control systems, having these file-scope copyright notices causes trouble when we update copyright years or refactor code. Over time, the file-scope copyright notices may become outdated as new contributions are made or code is moved from one file to another. Sometimes people contribute significant patches but do not add a line claiming copyright. Other times, people add a copyright notice for their contribution but then a later refactoring moves part or all of their contribution to another file and the notice is not moved with the code. As a practical matter, moving such notices is difficult -- determining what parts are due to a particular contributor requires a time-consuming search through the project history. Even managing the yearly update of copyright years is problematic. We have some contributors who are no longer living. Should we update the copyright dates for their contributions when we release new versions? Probably not, but we do still want to claim copyright for the project as a whole. To minimize the difficulty of maintaining the copyright notices, I would like to change Octave's sources to use what is described here: https://softwarefreedom.org/resources/2012/ManagingCopyrightInformation.html in the section "Maintaining centralized copyright notices": The centralized notice approach consolidates all copyright notices in a single location, usually a top-level file. This file should contain all of the copyright notices provided project contributors, unless the contribution was clearly insignificant. It may also credit -- without a copyright notice -- anyone who helped with the project but did not contribute code or other copyrighted material. This approach captures less information about contributions within individual files, recognizing that the DVCS is better equipped to record those details. As we mentioned before, it does have one disadvantage as compared to the file-scope approach: if a single file is separated from the distribution, the recipient won't see the contributors' copyright notices. But this can be easily remedied by including a single copyright notice in each file's header, pointing to the top-level file: Copyright YYYY-YYYY The Octave Project Developers See the COPYRIGHT file at the top-level directory of this distribution or at https://octave.org/COPYRIGHT.html. followed by the usual GPL copyright statement. For more background, see the discussion here: https://lists.gnu.org/archive/html/octave-maintainers/2020-01/msg00009.html Most files in the following directories have been skipped intentinally in this changeset: doc libgui/qterminal liboctave/external m4
author John W. Eaton <jwe@octave.org>
date Mon, 06 Jan 2020 15:38:17 -0500
parents 3621f0bb50bb
children 1891570abac8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27858
diff changeset
1 ## Copyright (C) 2007-2019 The Octave Project Developers
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27858
diff changeset
2 ##
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27858
diff changeset
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27858
diff changeset
4 ## or <https://octave.org/COPYRIGHT.html/>.
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27858
diff changeset
5 ##
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
6 ##
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
7 ## This file is part of Octave.
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
8 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
9 ## 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
10 ## 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
11 ## 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
12 ## (at your option) any later version.
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
13 ##
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
14 ## 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
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## GNU General Public License for more details.
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
18 ##
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
19 ## 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
20 ## 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
21 ## <https://www.gnu.org/licenses/>.
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
22
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
23 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20735
diff changeset
24 ## @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
25 ## @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
26 ## @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
27 ## @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
28 ## @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
29 ## @deftypefnx {} {@var{vi} =} interpn (@dots{}, @var{method}, @var{extrapval})
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
30 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
31 ## 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
32 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
33 ## 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
34 ## 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
35 ## 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
36 ## @var{n}-dimensional arrays of the same size as the array @var{v} in
27858
3621f0bb50bb doc: Use Texinfo commands to stop "etc." causing a sentence break.
Rik <rik@octave.org>
parents: 26379
diff changeset
37 ## the @qcode{"ndgrid"} format or vectors. The parameters @var{y1}, etc.@:
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16891
diff changeset
38 ## respect a similar format to @var{x1}, etc., and they represent the points
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16891
diff changeset
39 ## at which the array @var{vi} is interpolated.
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
40 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
41 ## 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
42 ## @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
43 ## 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
44 ## 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
45 ## specified, then @var{m} is assumed to be @code{1}.
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
46 ##
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
47 ## The interpolation @var{method} is one of:
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
48 ##
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
49 ## @table @asis
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16891
diff changeset
50 ## @item @qcode{"nearest"}
9070
e9dc2ed2ec0f Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
51 ## Return the nearest neighbor.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10819
diff changeset
52 ##
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
53 ## @item @qcode{"linear"} (default)
9070
e9dc2ed2ec0f Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
54 ## Linear interpolation from nearest neighbors.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10819
diff changeset
55 ##
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
56 ## @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
57 ## 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
58 ## 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
59 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16891
diff changeset
60 ## @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
61 ## 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
62 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16891
diff changeset
63 ## @item @qcode{"spline"}
12175
2090995ca588 Correct en-dash,em-dash instances in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
64 ## Cubic spline interpolation---smooth first and second derivatives
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
65 ## throughout the curve.
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
66 ## @end table
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
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 ## The default method is @qcode{"linear"}.
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
69 ##
19795
ca7599ae464d doc: Grammarcheck documentation ahead of 4.0 release.
Rik <rik@octave.org>
parents: 19697
diff changeset
70 ## @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
71 ## 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
72 ## 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
73 ## @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
74 ## @qcode{"spline"} are used. Otherwise the default @var{extrapval} value for
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
75 ## any other @var{method} is @qcode{"NA"}.
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
76 ## @seealso{interp1, interp2, interp3, spline, ndgrid}
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
77 ## @end deftypefn
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
78
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
79 function vi = interpn (varargin)
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
80
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
81 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
82 extrapval = [];
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
83 nargs = nargin;
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
84
13151
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
85 if (nargin < 1 || ! isnumeric (varargin{1}))
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
86 print_usage ();
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
87 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
88
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
89 if (nargs > 1 && ischar (varargin{end-1}))
7208
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7016
diff changeset
90 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
91 error ("interpn: EXTRAPVAL must be a numeric scalar");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
92 endif
8116
6c69f5cda32b For for extrapval in interpn
Kris Thielemans
parents: 7671
diff changeset
93 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
94 method = varargin{end-1};
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
95 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
96 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
97 method = varargin{end};
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 20158
diff changeset
98 nargs -= 1;
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
99 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
100
18587
5cf9a02732b6 Issue warning when '*' flag used with interp2,3,n.m (bug #41459).
Rik <rik@octave.org>
parents: 17744
diff changeset
101 if (method(1) == "*")
5cf9a02732b6 Issue warning when '*' flag used with interp2,3,n.m (bug #41459).
Rik <rik@octave.org>
parents: 17744
diff changeset
102 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
103 method(1) = [];
5cf9a02732b6 Issue warning when '*' flag used with interp2,3,n.m (bug #41459).
Rik <rik@octave.org>
parents: 17744
diff changeset
104 endif
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 method = validatestring (method, ...
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
106 {"nearest", "linear", "pchip", "cubic", "spline"});
18587
5cf9a02732b6 Issue warning when '*' flag used with interp2,3,n.m (bug #41459).
Rik <rik@octave.org>
parents: 17744
diff changeset
107
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
108 if (nargs < 3)
7208
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7016
diff changeset
109 v = varargin{1};
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
110 m = 1;
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
111 if (nargs == 2)
13151
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
112 if (ischar (varargin{2}))
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
113 method = varargin{2};
13161
6b6d0e51bd2f scripts/general/interpn.m: fix(m)==m is faster than round(m)==m
Ben Abbott <bpabbott@mac.com>
parents: 13151
diff changeset
114 elseif (isnumeric (m) && isscalar (m) && fix (m) == m)
13151
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
115 m = varargin{2};
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
116 else
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
117 print_usage ();
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
118 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
119 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
120 sz = size (v);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
121 nd = ndims (v);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
122 x = cell (1, nd);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
123 y = cell (1, nd);
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
124 for i = 1 : nd
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
125 x{i} = 1 : sz(i);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
126 y{i} = 1 : (1 / (2 ^ m)) : sz(i);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
127 endfor
13151
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
128 y{1} = y{1}.';
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
129 [y{:}] = ndgrid (y{:});
7208
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7016
diff changeset
130 elseif (! isvector (varargin{1}) && nargs == (ndims (varargin{1}) + 1))
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7016
diff changeset
131 v = varargin{1};
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
132 sz = size (v);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
133 nd = ndims (v);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
134 x = cell (1, nd);
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
135 y = varargin(2 : nargs);
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
136 for i = 1 : nd
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
137 x{i} = 1 : sz(i);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
138 endfor
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
139 elseif (rem (nargs, 2) == 1
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
140 && nargs == (2 * ndims (varargin{ceil (nargs / 2)})) + 1)
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
141 nv = ceil (nargs / 2);
7208
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7016
diff changeset
142 v = varargin{nv};
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
143 sz = size (v);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
144 nd = ndims (v);
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
145 x = varargin(1 : (nv - 1));
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
146 y = varargin((nv + 1) : nargs);
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
147 else
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
148 error ("interpn: wrong number or incorrectly formatted input arguments");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
149 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
150
12931
cefd568ea073 Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents: 12175
diff changeset
151 if (any (! cellfun ("isvector", x)))
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
152 for i = 2 : nd
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
153 if (! size_equal (x{1}, x{i}) || ! size_equal (x{i}, v))
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
154 error ("interpn: dimensional mismatch");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
155 endif
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
156 idx(1 : nd) = {1};
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
157 idx(i) = ":";
6721
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
158 x{i} = x{i}(idx{:})(:);
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
159 endfor
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
160 idx(1 : nd) = {1};
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
161 idx(1) = ":";
6721
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
162 x{1} = x{1}(idx{:})(:);
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
163 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
164
7421
1c7b3e1fda19 [project @ 2008-01-25 21:00:42 by dbateman]
dbateman
parents: 7208
diff changeset
165 method = tolower (method);
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
166
12931
cefd568ea073 Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents: 12175
diff changeset
167 all_vectors = all (cellfun ("isvector", y));
cefd568ea073 Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents: 12175
diff changeset
168 different_lengths = numel (unique (cellfun ("numel", y))) > 1;
10819
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
169 if (all_vectors && different_lengths)
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
170 [foobar(1:numel(y)).y] = ndgrid (y{:});
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
171 y = {foobar.y};
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
172 endif
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
173
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
174 if (strcmp (method, "linear"))
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
175 vi = __lin_interpn__ (x{:}, 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
176 if (isempty (extrapval))
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
177 extrapval = NA;
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
178 endif
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
179 vi(isna (vi)) = extrapval;
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
180 elseif (strcmp (method, "nearest"))
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
181 yshape = size (y{1});
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
182 yidx = cell (1, nd);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
183 for i = 1 : nd
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
184 y{i} = y{i}(:);
7671
4fbaba9abec1 implement compiled binary lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 7561
diff changeset
185 yidx{i} = lookup (x{i}, y{i}, "lr");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
186 endfor
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
187 idx = cell (1,nd);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
188 for i = 1 : nd
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19795
diff changeset
189 idx{i} = yidx{i} ...
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19795
diff changeset
190 + (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
191 endfor
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
192 vi = v(sub2ind (sz, idx{:}));
10819
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
193 idx = zeros (prod (yshape), 1);
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
194 for i = 1 : nd
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
195 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
196 endfor
19658
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
197 if (isempty (extrapval))
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
198 extrapval = NA;
5a59c0e1203d Modified the "extrap" option for interp2, interp3, and interpn (bug #44002).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18587
diff changeset
199 endif
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
200 vi(idx) = extrapval;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
201 vi = reshape (vi, yshape);
6721
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
202 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
203 if (any (! cellfun ("isvector", y)))
7423
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
204 for i = 2 : nd
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
205 if (! size_equal (y{1}, y{i}))
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
206 error ("interpn: dimensional mismatch");
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
207 endif
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
208 idx(1 : nd) = {1};
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
209 idx(i) = ":";
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
210 y{i} = y{i}(idx{:});
7423
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
211 endfor
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
212 idx(1 : nd) = {1};
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
213 idx(1) = ":";
7423
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
214 y{1} = y{1}(idx{:});
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
215 endif
7421
1c7b3e1fda19 [project @ 2008-01-25 21:00:42 by dbateman]
dbateman
parents: 7208
diff changeset
216
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
217 vi = __splinen__ (x, v, y, extrapval, "interpn");
7421
1c7b3e1fda19 [project @ 2008-01-25 21:00:42 by dbateman]
dbateman
parents: 7208
diff changeset
218
7423
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
219 if (size_equal (y{:}))
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
220 ly = length (y{1});
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
221 idx = cell (1, ly);
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
222 q = cell (1, nd);
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
223 for i = 1 : ly
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
224 q(:) = i;
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
225 idx{i} = q;
7423
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
226 endfor
16891
486c3e2731ff interpn.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 14868
diff changeset
227 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
228 vi = reshape (vi, size (y{1}));
7423
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
229 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
230 elseif (strcmp (method, "cubic"))
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
231 error ("interpn: cubic interpolation not yet implemented");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
232 else
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 10846
diff changeset
233 error ("interpn: unrecognized interpolation METHOD");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
234 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
235
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
236 endfunction
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
237
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
238
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
239 %!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
240 %! 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
241 %! 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
242 %! 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
243 %! 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
244 %! 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
245 %! 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
246 %! 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
247 %! [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
248 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off;
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
249
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
250 %!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
251 %! 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
252 %! 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
253 %! 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
254 %! 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
255 %! 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
256 %! 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
257 %! 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
258 %! [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
259 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off;
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
260
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 %!#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
262 %! 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
263 %! 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
264 %! 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
265 %! 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
266 %! 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
267 %! 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
268 %! 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
269 %! [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
270 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off;
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
271
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
272 %!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
273 %! 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
274 %! 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
275 %! 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
276 %! 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
277 %! 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
278 %! 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
279 %! 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
280 %! [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
281 %! 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
282
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
283 %!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
284 %! 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
285 %! colormap ("default");
6721
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
286 %! x = y = z = -1:1;
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
287 %! f = @(x,y,z) x.^2 - y - z.^2;
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
288 %! [xx, yy, zz] = meshgrid (x, y, z);
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
289 %! v = f (xx,yy,zz);
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
290 %! xi = yi = zi = -1:0.1:1;
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
291 %! [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
292 %! 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
293 %! mesh (yi, zi, squeeze (vi(1,:,:)));
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
294
7421
1c7b3e1fda19 [project @ 2008-01-25 21:00:42 by dbateman]
dbateman
parents: 7208
diff changeset
295 %!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
296 %! [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
297 %! 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
298 %! assert (interpn (x,y,z,f,[.5 1.5],[.5 1.5],[.5 1.5]), [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
299 %! assert (interpn (x,y,z,f,[.51 1.51],[.51 1.51],[.51 1.51],"nearest"), [3, 6]);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
300 %! 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
301 %! 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
302 %! 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
303 %! 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
304
a938cd7869b2 __lin_interpn__.cc: handle decreasing coordinate values
Alexander Barth
parents: 7424
diff changeset
305 %!test
10819
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
306 %! [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
307 %! 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
308 %! 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
309 %! 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
310 %! [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
311 %! 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
312
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
313 %!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
314 %! 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
315 %! [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
316 %! 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
317 %! 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
318 %! 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
319
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
320 %!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
321 %! [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
322 %! 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
323 %! 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
324
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
325 %!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
326 %! 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
327 %! 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
328
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
329 %!test
13151
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
330 %! z = zeros (3, 3, 3);
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
331 %! zout = zeros (5, 5, 5);
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
332 %! z(:,:,1) = [1 3 5; 3 5 7; 5 7 9];
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
333 %! z(:,:,2) = z(:,:,1) + 2;
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
334 %! z(:,:,3) = z(:,:,2) + 2;
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
335 %! for n = 1:5
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
336 %! 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
337 %! 2 3 4 5 6;
13151
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
338 %! 3 4 5 6 7;
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
339 %! 4 5 6 7 8;
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
340 %! 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
341 %! endfor
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
342 %! 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
343 %! 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
344 %! 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
345 %! 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
346
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19795
diff changeset
347 ## Test input validation
18587
5cf9a02732b6 Issue warning when '*' flag used with interp2,3,n.m (bug #41459).
Rik <rik@octave.org>
parents: 17744
diff changeset
348 %!warning <ignoring unsupported '\*' flag> interpn (rand (3,3), 1, "*linear");