annotate scripts/general/interp3.m @ 17535:c12c688a35ed default tip lyh

Fix warnings
author LYH <lyh.kernel@gmail.com>
date Fri, 27 Sep 2013 17:43:27 +0800
parents bc924baa2c4e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 13153
diff changeset
1 ## Copyright (C) 2007-2012 David Bateman
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
2 ##
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
3 ## This file is part of Octave.
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
4 ##
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
8 ## your option) any later version.
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
9 ##
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
10 ## 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
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
13 ## General Public License for more details.
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 ## 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
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
17 ## <http://www.gnu.org/licenses/>.
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 ## -*- texinfo -*-
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
20 ## @deftypefn {Function File} {@var{vi} =} interp3 (@var{x}, @var{y}, @var{z}, @var{v}, @var{xi}, @var{yi}, @var{zi})
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
21 ## @deftypefnx {Function File} {@var{vi} =} interp3 (@var{v}, @var{xi}, @var{yi}, @var{zi})
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
22 ## @deftypefnx {Function File} {@var{vi} =} interp3 (@var{v}, @var{m})
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
23 ## @deftypefnx {Function File} {@var{vi} =} interp3 (@var{v})
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
24 ## @deftypefnx {Function File} {@var{vi} =} interp3 (@dots{}, @var{method})
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
25 ## @deftypefnx {Function File} {@var{vi} =} interp3 (@dots{}, @var{method}, @var{extrapval})
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
26 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
27 ## Perform 3-dimensional interpolation. Each element of the 3-dimensional
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
28 ## array @var{v} represents a value at a location given by the parameters
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
29 ## @var{x}, @var{y}, and @var{z}. The parameters @var{x}, @var{x}, and
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
30 ## @var{z} are either 3-dimensional arrays of the same size as the array
17289
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15333
diff changeset
31 ## @var{v} in the @qcode{"meshgrid"} format or vectors. The parameters
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15333
diff changeset
32 ## @var{xi}, etc. respect a similar format to @var{x}, etc., and they
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15333
diff changeset
33 ## represent the points at which the array @var{vi} is interpolated.
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
34 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
35 ## If @var{x}, @var{y}, @var{z} are omitted, they are assumed to be
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
36 ## @code{x = 1 : size (@var{v}, 2)}, @code{y = 1 : size (@var{v}, 1)} and
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
37 ## @code{z = 1 : size (@var{v}, 3)}. If @var{m} is specified, then
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
38 ## 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: 11563
diff changeset
39 ## 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
40 ## specified, then @var{m} is assumed to be @code{1}.
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
41 ##
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
42 ## Method is one of:
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
43 ##
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
44 ## @table @asis
17289
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15333
diff changeset
45 ## @item @qcode{"nearest"}
9070
e9dc2ed2ec0f Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
46 ## Return the nearest neighbor.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
47 ##
17289
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15333
diff changeset
48 ## @item @qcode{"linear"}
9070
e9dc2ed2ec0f Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
49 ## Linear interpolation from nearest neighbors.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
50 ##
17289
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15333
diff changeset
51 ## @item @qcode{"cubic"}
9070
e9dc2ed2ec0f Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
52 ## Cubic interpolation from four nearest neighbors (not implemented yet).
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
53 ##
17289
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15333
diff changeset
54 ## @item @qcode{"spline"}
12175
2090995ca588 Correct en-dash,em-dash instances in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
55 ## Cubic spline interpolation---smooth first and second derivatives
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
56 ## throughout the curve.
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
57 ## @end table
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
58 ##
17289
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15333
diff changeset
59 ## The default method is @qcode{"linear"}.
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
60 ##
17289
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15333
diff changeset
61 ## If @var{extrap} is the string @qcode{"extrap"}, then extrapolate values
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15333
diff changeset
62 ## beyond the endpoints. If @var{extrap} is a number, replace values beyond
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15333
diff changeset
63 ## the endpoints with that number. If @var{extrap} is missing, assume NA.
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
64 ## @seealso{interp1, interp2, spline, meshgrid}
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
65 ## @end deftypefn
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
66
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
67 function vi = interp3 (varargin)
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
68 method = "linear";
6742
ebf96cc00ee9 [project @ 2007-06-18 16:27:52 by jwe]
jwe
parents: 6722
diff changeset
69 extrapval = NA;
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
70 nargs = nargin;
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
71
13151
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 13150
diff changeset
72 if (nargin < 1 || ! isnumeric (varargin{1}))
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
73 print_usage ();
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
74 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
75
7174
ff4a4cc863a9 [project @ 2007-11-14 19:16:12 by jwe]
jwe
parents: 7016
diff changeset
76 if (ischar (varargin{end}))
ff4a4cc863a9 [project @ 2007-11-14 19:16:12 by jwe]
jwe
parents: 7016
diff changeset
77 method = varargin{end};
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
78 nargs = nargs - 1;
13151
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 13150
diff changeset
79 elseif (nargs > 1 && ischar (varargin{end - 1}))
7174
ff4a4cc863a9 [project @ 2007-11-14 19:16:12 by jwe]
jwe
parents: 7016
diff changeset
80 if (! isnumeric (varargin{end}) || ! isscalar (varargin{end}))
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
81 error ("interp3: extrapal is expected to be a numeric scalar");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
82 endif
7174
ff4a4cc863a9 [project @ 2007-11-14 19:16:12 by jwe]
jwe
parents: 7016
diff changeset
83 extrapval = varargin{end};
ff4a4cc863a9 [project @ 2007-11-14 19:16:12 by jwe]
jwe
parents: 7016
diff changeset
84 method = varargin{end-1};
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
85 nargs = nargs - 2;
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
86 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
87
7174
ff4a4cc863a9 [project @ 2007-11-14 19:16:12 by jwe]
jwe
parents: 7016
diff changeset
88 if (nargs < 3 || (nargs == 4 && ! isvector (varargin{1})
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9246
diff changeset
89 && nargs == (ndims (varargin{1}) + 1)))
7174
ff4a4cc863a9 [project @ 2007-11-14 19:16:12 by jwe]
jwe
parents: 7016
diff changeset
90 v = varargin{1};
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
91 if (ndims (v) != 3)
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
92 error ("interp3: expect 3-dimensional array of values");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
93 endif
15333
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
94 x = varargin (2:nargs);
6722
5b09d433171c [project @ 2007-06-14 10:13:14 by dbateman]
dbateman
parents: 6702
diff changeset
95 if (any (! cellfun (@isvector, x)))
5b09d433171c [project @ 2007-06-14 10:13:14 by dbateman]
dbateman
parents: 6702
diff changeset
96 for i = 2 : 3
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9246
diff changeset
97 if (! size_equal (x{1}, x{i}))
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
98 error ("interp3: dimensional mismatch");
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9246
diff changeset
99 endif
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9246
diff changeset
100 x{i} = permute (x{i}, [2, 1, 3]);
6722
5b09d433171c [project @ 2007-06-14 10:13:14 by dbateman]
dbateman
parents: 6702
diff changeset
101 endfor
5b09d433171c [project @ 2007-06-14 10:13:14 by dbateman]
dbateman
parents: 6702
diff changeset
102 x{1} = permute (x{1}, [2, 1, 3]);
5b09d433171c [project @ 2007-06-14 10:13:14 by dbateman]
dbateman
parents: 6702
diff changeset
103 endif
5b09d433171c [project @ 2007-06-14 10:13:14 by dbateman]
dbateman
parents: 6702
diff changeset
104 v = permute (v, [2, 1, 3]);
5b09d433171c [project @ 2007-06-14 10:13:14 by dbateman]
dbateman
parents: 6702
diff changeset
105 vi = ipermute (interpn (v, x{:}, method, extrapval), [2, 1, 3]);
7174
ff4a4cc863a9 [project @ 2007-11-14 19:16:12 by jwe]
jwe
parents: 7016
diff changeset
106 elseif (nargs == 7 && nargs == (2 * ndims (varargin{ceil (nargs / 2)})) + 1)
ff4a4cc863a9 [project @ 2007-11-14 19:16:12 by jwe]
jwe
parents: 7016
diff changeset
107 v = varargin{4};
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
108 if (ndims (v) != 3)
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
109 error ("interp3: expect 3-dimensional array of values");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
110 endif
6722
5b09d433171c [project @ 2007-06-14 10:13:14 by dbateman]
dbateman
parents: 6702
diff changeset
111 x = varargin (1:3);
5b09d433171c [project @ 2007-06-14 10:13:14 by dbateman]
dbateman
parents: 6702
diff changeset
112 if (any (! cellfun (@isvector, x)))
5b09d433171c [project @ 2007-06-14 10:13:14 by dbateman]
dbateman
parents: 6702
diff changeset
113 for i = 2 : 3
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9246
diff changeset
114 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
115 error ("interp3: dimensional mismatch");
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9246
diff changeset
116 endif
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9246
diff changeset
117 x{i} = permute (x{i}, [2, 1, 3]);
6722
5b09d433171c [project @ 2007-06-14 10:13:14 by dbateman]
dbateman
parents: 6702
diff changeset
118 endfor
5b09d433171c [project @ 2007-06-14 10:13:14 by dbateman]
dbateman
parents: 6702
diff changeset
119 x{1} = permute (x{1}, [2, 1, 3]);
5b09d433171c [project @ 2007-06-14 10:13:14 by dbateman]
dbateman
parents: 6702
diff changeset
120 endif
5b09d433171c [project @ 2007-06-14 10:13:14 by dbateman]
dbateman
parents: 6702
diff changeset
121 y = varargin (5:7);
5b09d433171c [project @ 2007-06-14 10:13:14 by dbateman]
dbateman
parents: 6702
diff changeset
122 if (any (! cellfun (@isvector, y)))
5b09d433171c [project @ 2007-06-14 10:13:14 by dbateman]
dbateman
parents: 6702
diff changeset
123 for i = 2 : 3
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9246
diff changeset
124 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
125 error ("interp3: dimensional mismatch");
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9246
diff changeset
126 endif
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9246
diff changeset
127 y{i} = permute (y{i}, [2, 1, 3]);
6722
5b09d433171c [project @ 2007-06-14 10:13:14 by dbateman]
dbateman
parents: 6702
diff changeset
128 endfor
5b09d433171c [project @ 2007-06-14 10:13:14 by dbateman]
dbateman
parents: 6702
diff changeset
129 y{1} = permute (y{1}, [2, 1, 3]);
5b09d433171c [project @ 2007-06-14 10:13:14 by dbateman]
dbateman
parents: 6702
diff changeset
130 endif
5b09d433171c [project @ 2007-06-14 10:13:14 by dbateman]
dbateman
parents: 6702
diff changeset
131 v = permute (v, [2, 1, 3]);
7174
ff4a4cc863a9 [project @ 2007-11-14 19:16:12 by jwe]
jwe
parents: 7016
diff changeset
132 vi = ipermute (interpn (x{:}, v, y{:}, method, extrapval), [2, 1, 3]);
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
133 else
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
134 error ("interp3: wrong number or incorrectly formatted input arguments");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
135 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
136 endfunction
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
137
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
138
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
139 %!test
15333
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
140 %! x = y = z = -1:1; y = y + 2;
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
141 %! f = @(x,y,z) x.^2 - y - z.^2;
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
142 %! [xx, yy, zz] = meshgrid (x, y, z);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
143 %! v = f (xx,yy,zz);
15333
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
144 %! xi = yi = zi = -1:0.5:1; yi = yi + 2.1;
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
145 %! [xxi, yyi, zzi] = meshgrid (xi, yi, zi);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
146 %! vi = interp3 (x, y, z, v, xxi, yyi, zzi);
15333
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
147 %! [xxi, yyi, zzi] = ndgrid (yi, xi, zi);
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
148 %! vi2 = interpn (y, x, z, v, xxi, yyi, zzi);
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
149 %! tol = 10 * eps;
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
150 %! assert (vi, vi2, tol);
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
151
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
152 %!test
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
153 %! x=z=1:2; y=1:3;xi=zi=.6:1.6; yi=1; v=ones([3,2,2]); v(:,2,1)=[7 ;5;4]; v(:,1,2)=[2 ;3;5];
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
154 %! [xxi3, yyi3, zzi3] = meshgrid (xi, yi, zi);
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
155 %! [xxi, yyi, zzi] = ndgrid (yi, xi, zi);
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
156 %! vi = interp3 (x, y, z, v, xxi3, yyi3, zzi3, "nearest");
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
157 %! vi2 = interpn (y, x, z, v, xxi, yyi, zzi,"nearest");
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
158 %! assert (vi, vi2);
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
159
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
160 %!test
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
161 %! x=z=1:2; y=1:3;xi=zi=.6:1.6; yi=1; v=ones([3,2,2]); v(:,2,1)=[7 ;5;4]; v(:,1,2)=[2 ;3;5];
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
162 %! vi = interp3 (x, y, z, v, xi+1, yi, zi, "nearest",3);
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
163 %! vi2 = interpn (y, x, z, v, yi, xi+1, zi,"nearest", 3);
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
164 %! assert (vi, vi2);
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
165
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
166 %!test
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
167 %! x=z=1:2; y=1:3;xi=zi=.6:1.6; yi=1; v=ones([3,2,2]); v(:,2,1)=[7 ;5;4]; v(:,1,2)=[2 ;3;5];
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
168 %! vi = interp3 (x, y, z, v, xi, yi, zi, "nearest");
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
169 %! vi2 = interpn (y, x, z, v, yi, xi, zi,"nearest");
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
170 %! assert (vi, vi2);
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
171
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
172 %!test
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
173 %! x=z=1:2; y=1:3;xi=zi=.6:1.6; yi=1; v=ones([3,2,2]); v(:,2,1)=[7 ;5;4]; v(:,1,2)=[2 ;3;5];
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
174 %! vi = interp3 (v, xi, yi, zi, "nearest",3);
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
175 %! vi2 = interpn (v, yi, xi, zi,"nearest", 3);
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
176 %! assert (vi, vi2);
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
177
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
178 %!test
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
179 %! xi=zi=.6:1.6; yi=1; v=ones([3,2,2]); v(:,2,1)=[7 ;5;4]; v(:,1,2)=[2 ;3;5];
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
180 %! vi = interp3 (v, xi, yi, zi, "nearest");
7d2eb4a01798 fix problem in interp3.m when method argument is passed, added tests, and made one test more stringent
Kris Thielemans <kris.f.thielemans@gmail.com>
parents: 14363
diff changeset
181 %! vi2 = interpn (v, yi, xi, zi,"nearest");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
182 %! assert (vi, vi2);
13151
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 13150
diff changeset
183
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 13150
diff changeset
184 %!shared z, zout, tol
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 13150
diff changeset
185 %! z = zeros (3, 3, 3);
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 13150
diff changeset
186 %! zout = zeros (5, 5, 5);
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 13150
diff changeset
187 %! z(:,:,1) = [1 3 5; 3 5 7; 5 7 9];
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 13150
diff changeset
188 %! z(:,:,2) = z(:,:,1) + 2;
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 13150
diff changeset
189 %! z(:,:,3) = z(:,:,2) + 2;
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 13150
diff changeset
190 %! for n = 1:5
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 13150
diff changeset
191 %! zout(:,:,n) = [1 2 3 4 5;
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 13150
diff changeset
192 %! 2 3 4 5 6;
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 13150
diff changeset
193 %! 3 4 5 6 7;
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 13150
diff changeset
194 %! 4 5 6 7 8;
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 13150
diff changeset
195 %! 5 6 7 8 9] + (n-1);
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 13150
diff changeset
196 %! end
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 13150
diff changeset
197 %! tol = 10 * eps;
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 13150
diff changeset
198 %!assert (interp3 (z), zout, tol)
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 13150
diff changeset
199 %!assert (interp3 (z, "linear"), zout, tol)
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 13150
diff changeset
200 %!assert (interp3 (z, "spline"), zout, tol)
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
201