annotate scripts/general/interp2.m @ 19010:3fb030666878 draft default tip dspies

Added special-case logical-indexing function * logical-index.h (New file) : Logical-indexing function. May be called on octave_value types via call_bool_index * nz-iterators.h : Add base-class nz_iterator for iterator types. Array has template bool for whether to internally store row-col or compute on the fly Add skip_ahead method which skips forward to the next nonzero after its argument Add flat_index for computing octave_idx_type index of current position (with assertion failure in the case of overflow) Move is_zero to separate file * ov-base-diag.cc, ov-base-mat.cc, ov-base-sparse.cc, ov-perm.cc (do_index_op): Add call to call_bool_index in logical-index.h * Array.h : Move forward-declaration for array_iterator to separate header file * dim-vector.cc (dim_max): Refers to idx-bounds.h (max_idx) * array-iter-decl.h (New file): Header file for forward declaration of array-iterator * direction.h : Add constants fdirc and bdirc to avoid having to reconstruct them * dv-utils.h, dv-utils.cc (New files) : Utility functions for querying and constructing dim-vectors * idx-bounds.h (New file) : Utility constants and functions for determining whether things will overflow the maximum allowed bounds * interp-idx.h (New function : to_flat_idx) : Converts row-col pair to linear index of octave_idx_type * is-zero.h (New file) : Function for determining whether an element is zero * logical-index.tst : Add tests for correct return-value dimensions and large sparse matrix behavior
author David Spies <dnspies@gmail.com>
date Fri, 25 Jul 2014 13:39:31 -0600
parents 900b524d9072
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
1 ## Copyright (C) 2000-2013 Kai Habel
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2 ## Copyright (C) 2009 Jaroslav Hajek
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
3 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
4 ## This file is part of Octave.
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
5 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
7 ## 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
8 ## 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
9 ## your option) any later version.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
10 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
14 ## General Public License for more details.
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
15 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
16 ## 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
17 ## 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
18 ## <http://www.gnu.org/licenses/>.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
19
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
20 ## -*- texinfo -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
21 ## @deftypefn {Function File} {@var{zi} =} interp2 (@var{x}, @var{y}, @var{z}, @var{xi}, @var{yi})
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
22 ## @deftypefnx {Function File} {@var{zi} =} interp2 (@var{z}, @var{xi}, @var{yi})
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
23 ## @deftypefnx {Function File} {@var{zi} =} interp2 (@var{z}, @var{n})
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
24 ## @deftypefnx {Function File} {@var{zi} =} interp2 (@var{z})
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
25 ## @deftypefnx {Function File} {@var{zi} =} interp2 (@dots{}, @var{method})
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
26 ## @deftypefnx {Function File} {@var{zi} =} interp2 (@dots{}, @var{method}, @var{extrap})
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
27 ##
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
28 ## Two-dimensional interpolation.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
29 ##
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
30 ## Interpolate reference data @var{x}, @var{y}, @var{z} to determine @var{zi}
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
31 ## at the coordinates @var{xi}, @var{yi}. The reference data @var{x}, @var{y}
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
32 ## can be matrices, as returned by @code{meshgrid}, in which case the sizes of
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
33 ## @var{x}, @var{y}, and @var{z} must be equal. If @var{x}, @var{y} are
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
34 ## vectors describing a grid then @code{length (@var{x}) == columns (@var{z})}
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
35 ## and @code{length (@var{y}) == rows (@var{z})}. In either case the input
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
36 ## data must be strictly monotonic.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
37 ##
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
38 ## If called without @var{x}, @var{y}, and just a single reference data matrix
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
39 ## @var{z}, the 2-D region
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
40 ## @code{@var{x} = 1:columns (@var{z}), @var{y} = 1:rows (@var{z})} is assumed.
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
41 ## This saves memory if the grid is regular and the distance between points is
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
42 ## not important.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
43 ##
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
44 ## If called with a single reference data matrix @var{z} and a refinement
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
45 ## value @var{n}, then perform interpolation over a grid where each original
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
46 ## interval has been recursively subdivided @var{n} times. This results in
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
47 ## @code{2^@var{n}-1} additional points for every interval in the original
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
48 ## grid. If @var{n} is omitted a value of 1 is used. As an example, the
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
49 ## interval [0,1] with @code{@var{n}==2} results in a refined interval with
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
50 ## points at [0, 1/4, 1/2, 3/4, 1].
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
51 ##
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
52 ## The interpolation @var{method} is one of:
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
53 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
54 ## @table @asis
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15467
diff changeset
55 ## @item @qcode{"nearest"}
6218
c1b66b74937d [project @ 2006-12-27 17:43:50 by jwe]
jwe
parents: 6157
diff changeset
56 ## Return the nearest neighbor.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
57 ##
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
58 ## @item @qcode{"linear"} (default)
6218
c1b66b74937d [project @ 2006-12-27 17:43:50 by jwe]
jwe
parents: 6157
diff changeset
59 ## Linear interpolation from nearest neighbors.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
60 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15467
diff changeset
61 ## @item @qcode{"pchip"}
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
62 ## Piecewise cubic Hermite interpolating polynomial---shape-preserving
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
63 ## interpolation with smooth first derivative.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
64 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15467
diff changeset
65 ## @item @qcode{"cubic"}
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
66 ## Cubic interpolation (same as @qcode{"pchip"}).
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
67 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15467
diff changeset
68 ## @item @qcode{"spline"}
12175
2090995ca588 Correct en-dash,em-dash instances in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11589
diff changeset
69 ## Cubic spline interpolation---smooth first and second derivatives
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
70 ## throughout the curve.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
71 ## @end table
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
72 ##
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
73 ## If @var{extrap} is the string @qcode{"extrap"}, then extrapolate values
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
74 ## beyond the endpoints using the current @var{method}. If @var{extrap} is a
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
75 ## number, then replace values beyond the endpoints with that number. When
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
76 ## unspecified, @var{extrap} defaults to @code{NA}. Note that if @var{extrap}
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
77 ## is used, @var{method} must be specified as well.
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
78 ## @seealso{interp1, interp3, interpn, meshgrid}
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
79 ## @end deftypefn
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
80
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
81 ## Author: Kai Habel <kai.habel@gmx.de>
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
82 ## 2005-03-02 Thomas Weber <weber@num.uni-sb.de>
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
83 ## * Add test cases
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
84 ## 2005-03-02 Paul Kienzle <pkienzle@users.sf.net>
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
85 ## * Simplify
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
86 ## 2005-04-23 Dmitri A. Sergatskov <dasergatskov@gmail.com>
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
87 ## * Modified demo and test for new gnuplot interface
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
88 ## 2005-09-07 Hoxide <hoxide_dirac@yahoo.com.cn>
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
89 ## * Add bicubic interpolation method
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
90 ## * Fix the eat line bug when the last element of XI or YI is
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
91 ## negative or zero.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
92 ## 2005-11-26 Pierre Baldensperger <balden@libertysurf.fr>
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
93 ## * Rather big modification (XI,YI no longer need to be
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
94 ## "meshgridded") to be consistent with the help message
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
95 ## above and for compatibility.
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
96
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
97 ## FIXME: Need better input validation.
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
98 ## E.g, interp2 (1,1,1) => A(I): index out of bounds
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
99
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
100 function ZI = interp2 (varargin)
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
101
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
102 Z = X = Y = XI = YI = n = [];
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
103 method = "linear";
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
104 extrap = NA;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
105
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
106 switch (nargin)
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
107 case 1
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
108 Z = varargin{1};
13149
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
109 n = 1;
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
110 case 2
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
111 if (ischar (varargin{2}))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
112 [Z, method] = deal (varargin{:});
13149
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
113 n = 1;
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
114 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
115 [Z, n] = deal (varargin{:});
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
116 endif
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
117 case 3
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
118 if (ischar (varargin{3}))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
119 [Z, n, method] = deal (varargin{:});
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
120 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
121 [Z, XI, YI] = deal (varargin{:});
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
122 endif
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
123 case 4
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
124 if (ischar (varargin{4}))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
125 [Z, XI, YI, method] = deal (varargin{:});
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
126 else
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
127 [Z, n, method, extrap] = deal (varargin{:});
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
128 endif
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
129 case 5
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
130 if (ischar (varargin{4}))
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
131 [Z, XI, YI, method, extrap] = deal (varargin{:});
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
132 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
133 [X, Y, Z, XI, YI] = deal (varargin{:});
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
134 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
135 case 6
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
136 [X, Y, Z, XI, YI, method] = deal (varargin{:});
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
137 case 7
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
138 [X, Y, Z, XI, YI, method, extrap] = deal (varargin{:});
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
139 otherwise
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
140 print_usage ();
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
141 endswitch
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
142
18641
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
143 ## Type checking
18664
900b524d9072 interp2: Verify Z matrix is 2-D (bug #41267).
Rik <rik@octave.org>
parents: 18641
diff changeset
144 if (! (ismatrix (Z) && ndims (Z) == 2))
900b524d9072 interp2: Verify Z matrix is 2-D (bug #41267).
Rik <rik@octave.org>
parents: 18641
diff changeset
145 error ("interp2: Z must be a 2-D matrix");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
146 endif
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
147 if (! isempty (n) && ! (isscalar (n) && n >= 0 && n == fix (n)))
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
148 error ("interp2: N must be an integer >= 0");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
149 endif
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
150 if (! ischar (method))
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
151 error ("interp2: METHOD must be a string");
18641
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
152 elseif (method(1) == "*")
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
153 warning ("interp2: ignoring unsupported '*' flag to METHOD");
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
154 method(1) = [];
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
155 endif
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
156 if (isnumeric (extrap) && isscalar (extrap))
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
157 ## Typical case
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
158 elseif (strcmp (extrap, "extrap"))
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
159 extrap = [];
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
160 else
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
161 error ('interp2: EXTRAP must be a numeric scalar or "extrap"');
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
162 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
163
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
164 ## Define X, Y, XI, YI if needed
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
165 [zr, zc] = size (Z);
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
166 if (isempty (X))
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
167 X = 1:zc;
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
168 Y = 1:zr;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
169 endif
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
170 if (! isnumeric (X) || ! isnumeric (Y))
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
171 error ("interp2: X, Y must be numeric matrices");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
172 endif
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
173 if (! isempty (n))
13149
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
174 ## Calculate the interleaved input vectors.
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
175 p = 2^n;
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
176 XI = (p:p*zc)/p;
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
177 YI = (p:p*zr)'/p;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
178 endif
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
179 if (! isnumeric (XI) || ! isnumeric (YI))
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
180 error ("interp2: XI, YI must be numeric");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
181 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
182
18641
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
183 if (isvector (X) && isvector (Y))
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
184 X = X(:); Y = Y(:);
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
185 elseif (size_equal (X, Y))
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
186 X = X(1,:).'; Y = Y(:,1);
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
187 else
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
188 error ("interp2: X and Y must be matrices of equal size");
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
189 endif
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
190 if (columns (Z) != length (X) || rows (Z) != length (Y))
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
191 error ("interp2: X and Y size must match the dimensions of Z");
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
192 endif
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
193 dx = diff (X);
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
194 if (all (dx < 0))
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
195 X = flipud (X);
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
196 Z = fliplr (Z);
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
197 elseif (any (dx <= 0))
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
198 error ("interp2: X must be strictly monotonic");
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
199 endif
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
200 dy = diff (Y);
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
201 if (all (dy < 0))
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
202 Y = flipud (Y);
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
203 Z = flipud (Z);
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
204 elseif (any (dy <= 0))
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
205 error ("interp2: Y must be strictly monotonic");
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
206 endif
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
207
18641
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
208 if (any (strcmp (method, {"nearest", "linear", "pchip", "cubic"})))
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
209
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
210 ## If Xi and Yi are vectors of different orientation build a grid
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
211 if ((rows (XI) == 1 && columns (YI) == 1)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
212 || (columns (XI) == 1 && rows (YI) == 1))
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
213 [XI, YI] = meshgrid (XI, YI);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
214 elseif (! size_equal (XI, YI))
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 11108
diff changeset
215 error ("interp2: XI and YI must be matrices of equal size");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
216 endif
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
217
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
218 ## if XI, YI are vectors, X and Y should share their orientation.
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
219 if (rows (XI) == 1)
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
220 if (rows (X) != 1)
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
221 X = X.';
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
222 endif
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
223 if (rows (Y) != 1)
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
224 Y = Y.';
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
225 endif
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
226 elseif (columns (XI) == 1)
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
227 if (columns (X) != 1)
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
228 X = X.';
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
229 endif
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
230 if (columns (Y) != 1)
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
231 Y = Y.';
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
232 endif
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
233 endif
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
234
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
235 xidx = lookup (X, XI, "lr");
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
236 yidx = lookup (Y, YI, "lr");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
237
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
238 if (strcmp (method, "linear"))
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
239 ## each quad satisfies the equation z(x,y)=a+b*x+c*y+d*xy
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
240 ##
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
241 ## a-b
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
242 ## | |
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
243 ## c-d
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
244 a = Z(1:(zr - 1), 1:(zc - 1));
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
245 b = Z(1:(zr - 1), 2:zc) - a;
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
246 c = Z(2:zr, 1:(zc - 1)) - a;
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
247 d = Z(2:zr, 2:zc) - a - b - c;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
248
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
249 ## scale XI, YI values to a 1-spaced grid
10326
ade59ae10e80 slight optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 10320
diff changeset
250 Xsc = (XI - X(xidx)) ./ (diff (X)(xidx));
ade59ae10e80 slight optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 10320
diff changeset
251 Ysc = (YI - Y(yidx)) ./ (diff (Y)(yidx));
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
252
10328
2210d3070543 further memory optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 10326
diff changeset
253 ## Get 2D index.
2210d3070543 further memory optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 10326
diff changeset
254 idx = sub2ind (size (a), yidx, xidx);
2210d3070543 further memory optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 10326
diff changeset
255 ## We can dispose of the 1D indices at this point to save memory.
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
256 clear xidx yidx;
10328
2210d3070543 further memory optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 10326
diff changeset
257
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
258 ## apply plane equation
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
259 ZI = a(idx) + b(idx).*Xsc + c(idx).*Ysc + d(idx).*Xsc.*Ysc;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
260
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
261 elseif (strcmp (method, "nearest"))
10427
62bb59f927b1 scripts/general/interp2.m, scripts/general/interpn.m: For nearest neighbour interpolation ceil (instead of floor) at the center of the data intervals to be compatible with Matlab. Add test.
Soren Hauberg <hauberg@gmail.com>
parents: 10328
diff changeset
262 ii = (XI - X(xidx) >= X(xidx + 1) - XI);
62bb59f927b1 scripts/general/interp2.m, scripts/general/interpn.m: For nearest neighbour interpolation ceil (instead of floor) at the center of the data intervals to be compatible with Matlab. Add test.
Soren Hauberg <hauberg@gmail.com>
parents: 10328
diff changeset
263 jj = (YI - Y(yidx) >= Y(yidx + 1) - YI);
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
264 idx = sub2ind (size (Z), yidx+jj, xidx+ii);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
265 ZI = Z(idx);
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
266
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
267 elseif (strcmp (method, "pchip") || strcmp (method, "cubic"))
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
268
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
269 if (length (X) < 2 || length (Y) < 2)
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
270 error ("interp2: %s requires at least 2 points in each dimension",
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
271 method);
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
272 endif
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
273
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
274 ## first order derivatives
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
275 DX = __pchip_deriv__ (X, Z, 2);
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
276 DY = __pchip_deriv__ (Y, Z, 1);
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
277 ## Compute mixed derivatives row-wise and column-wise, use the average.
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
278 DXY = (__pchip_deriv__ (X, DY, 2) + __pchip_deriv__ (Y, DX, 1))/2;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
279
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
280 ## do the bicubic interpolation
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
281 hx = diff (X); hx = hx(xidx);
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
282 hy = diff (Y); hy = hy(yidx);
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
283
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
284 tx = (XI - X(xidx)) ./ hx;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
285 ty = (YI - Y(yidx)) ./ hy;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
286
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
287 ## construct the cubic hermite base functions in x, y
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
288
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
289 ## formulas:
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
290 ## b{1,1} = ( 2*t.^3 - 3*t.^2 + 1);
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
291 ## b{2,1} = h.*( t.^3 - 2*t.^2 + t );
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
292 ## b{1,2} = (-2*t.^3 + 3*t.^2 );
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
293 ## b{2,2} = h.*( t.^3 - t.^2 );
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
294
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
295 ## optimized equivalents of the above:
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
296 t1 = tx.^2;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
297 t2 = tx.*t1 - t1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
298 xb{2,2} = hx.*t2;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
299 t1 = t2 - t1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
300 xb{2,1} = hx.*(t1 + tx);
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
301 t2 += t1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
302 xb{1,2} = -t2;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
303 xb{1,1} = t2 + 1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
304
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
305 t1 = ty.^2;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
306 t2 = ty.*t1 - t1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
307 yb{2,2} = hy.*t2;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
308 t1 = t2 - t1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
309 yb{2,1} = hy.*(t1 + ty);
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
310 t2 += t1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
311 yb{1,2} = -t2;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
312 yb{1,1} = t2 + 1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
313
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
314 ZI = zeros (size (XI));
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
315 for i = 1:2
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
316 for j = 1:2
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
317 zidx = sub2ind (size (Z), yidx+(j-1), xidx+(i-1));
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
318 ZI += xb{1,i} .* yb{1,j} .* Z(zidx);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
319 ZI += xb{2,i} .* yb{1,j} .* DX(zidx);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
320 ZI += xb{1,i} .* yb{2,j} .* DY(zidx);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
321 ZI += xb{2,i} .* yb{2,j} .* DXY(zidx);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
322 endfor
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
323 endfor
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
324
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
325 endif
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
326
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
327 if (! isempty (extrap))
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
328 ## set points outside the table to 'extrap'
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
329 if (X(1) < X(end))
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
330 if (Y(1) < Y(end))
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
331 ZI(XI < X(1,1) | XI > X(end) | YI < Y(1,1) | YI > Y(end)) = ...
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
332 extrap;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
333 else
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
334 ZI(XI < X(1) | XI > X(end) | YI < Y(end) | YI > Y(1)) = ...
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
335 extrap;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
336 endif
6979
2883ea1c5c18 [project @ 2007-10-08 20:23:48 by dbateman]
dbateman
parents: 6742
diff changeset
337 else
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
338 if (Y(1) < Y(end))
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
339 ZI(XI < X(end) | XI > X(1) | YI < Y(1) | YI > Y(end)) = ...
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
340 extrap;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
341 else
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
342 ZI(XI < X(1,end) | XI > X(1) | YI < Y(end) | YI > Y(1)) = ...
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
343 extrap;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
344 endif
6979
2883ea1c5c18 [project @ 2007-10-08 20:23:48 by dbateman]
dbateman
parents: 6742
diff changeset
345 endif
2883ea1c5c18 [project @ 2007-10-08 20:23:48 by dbateman]
dbateman
parents: 6742
diff changeset
346 endif
2883ea1c5c18 [project @ 2007-10-08 20:23:48 by dbateman]
dbateman
parents: 6742
diff changeset
347
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
348 else
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
349
10780
6e7590d003dc Fix bugs in interp2 (bug #29601)
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10635
diff changeset
350 ## Check dimensions of XI and YI
13149
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
351 if (isvector (XI) && isvector (YI) && ! size_equal (XI, YI))
18641
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
352 XI = XI(:).'; YI = YI(:);
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
353 elseif (! size_equal (XI, YI))
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 11108
diff changeset
354 error ("interp2: XI and YI must be matrices of equal size");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
355 endif
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
356
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
357 ## FIXME: Previously used algorithm for cubic.
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
358 ## This produced results within a few eps of "spline".
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
359 ## Matlab compatibility requires "cubic" to be a C1 algorithm
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
360 ## equivalent to "pchip" so this was commented out 2014/03/30.
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
361 ## This can be removed completely in the future if no problems are
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
362 ## encountered.
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
363 #{
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
364 if (strcmp (method, "cubic"))
13149
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
365 if (isgriddata (XI) && isgriddata (YI'))
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
366 ZI = bicubic (X, Y, Z, XI (1, :), YI (:, 1), extrap);
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
367 elseif (isgriddata (X) && isgriddata (Y'))
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
368 ## Allocate output
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
369 ZI = zeros (size (X));
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
370
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
371 ## Find inliers
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
372 inside = !(XI < X(1) | XI > X(end) | YI < Y(1) | YI > Y(end));
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
373
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
374 ## Scale XI and YI to match indices of Z
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
375 XI = (columns (Z) - 1) * (XI - X(1)) / (X(end) - X(1)) + 1;
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
376 YI = (rows (Z) - 1) * (YI - Y(1)) / (Y(end) - Y(1)) + 1;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
377
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
378 ## Start the real work
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
379 K = floor (XI);
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
380 L = floor (YI);
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
381
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
382 ## Coefficients
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
383 AY1 = bc (YI - L + 1);
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
384 AX1 = bc (XI - K + 1);
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
385 AY0 = bc (YI - L + 0);
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
386 AX0 = bc (XI - K + 0);
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
387 AY_1 = bc (YI - L - 1);
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
388 AX_1 = bc (XI - K - 1);
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
389 AY_2 = bc (YI - L - 2);
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
390 AX_2 = bc (XI - K - 2);
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
391
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
392 ## Perform interpolation
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
393 sz = size (Z);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
394 ZI = AY_2 .* AX_2 .* Z(sym_sub2ind (sz, L+2, K+2)) ...
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
395 + AY_2 .* AX_1 .* Z(sym_sub2ind (sz, L+2, K+1)) ...
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
396 + AY_2 .* AX0 .* Z(sym_sub2ind (sz, L+2, K)) ...
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
397 + AY_2 .* AX1 .* Z(sym_sub2ind (sz, L+2, K-1)) ...
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
398 + AY_1 .* AX_2 .* Z(sym_sub2ind (sz, L+1, K+2)) ...
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
399 + AY_1 .* AX_1 .* Z(sym_sub2ind (sz, L+1, K+1)) ...
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
400 + AY_1 .* AX0 .* Z(sym_sub2ind (sz, L+1, K)) ...
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
401 + AY_1 .* AX1 .* Z(sym_sub2ind (sz, L+1, K-1)) ...
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
402 + AY0 .* AX_2 .* Z(sym_sub2ind (sz, L, K+2)) ...
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
403 + AY0 .* AX_1 .* Z(sym_sub2ind (sz, L, K+1)) ...
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
404 + AY0 .* AX0 .* Z(sym_sub2ind (sz, L, K)) ...
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
405 + AY0 .* AX1 .* Z(sym_sub2ind (sz, L, K-1)) ...
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
406 + AY1 .* AX_2 .* Z(sym_sub2ind (sz, L-1, K+2)) ...
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
407 + AY1 .* AX_1 .* Z(sym_sub2ind (sz, L-1, K+1)) ...
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
408 + AY1 .* AX0 .* Z(sym_sub2ind (sz, L-1, K)) ...
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
409 + AY1 .* AX1 .* Z(sym_sub2ind (sz, L-1, K-1));
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
410 ZI (!inside) = extrap;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
411
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
412 else
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
413 error ("interp2: input data must have 'meshgrid' format");
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
414 endif
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
415 #}
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
416
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
417 if (strcmp (method, "spline"))
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
418 if (isgriddata (XI) && isgriddata (YI'))
18641
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
419 ZI = __splinen__ ({Y, X}, Z, {YI(:,1), XI(1,:)}, extrap,
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
420 "spline");
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
421 else
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
422 error ("interp2: XI, YI must have uniform spacing ('meshgrid' format)");
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
423 endif
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
424 else
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
425 error ("interp2: unrecognized interpolation method '%s'", method);
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
426 endif
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
427
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
428 endif
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
429
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
430 endfunction
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
431
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
432 function b = isgriddata (X)
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
433 d1 = diff (X, 1, 1);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
434 b = all (d1(:) == 0);
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
435 endfunction
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
436
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
437 ## Compute the bicubic interpolation coefficients
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
438 function o = bc (x)
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
439 x = abs (x);
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
440 o = zeros (size (x));
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
441 idx1 = (x < 1);
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
442 idx2 = !idx1 & (x < 2);
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
443 o(idx1) = 1 - 2.*x(idx1).^2 + x(idx1).^3;
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
444 o(idx2) = 4 - 8.*x(idx2) + 5.*x(idx2).^2 - x(idx2).^3;
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
445 endfunction
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
446
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
447 ## This version of sub2ind behaves as if the data was symmetrically padded
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
448 function ind = sym_sub2ind (sz, Y, X)
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
449 Y(Y < 1) = 1 - Y(Y < 1);
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
450 while (any (Y(:) > 2*sz(1)))
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
451 Y(Y > 2*sz(1)) = round (Y(Y > 2*sz(1)) / 2);
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
452 endwhile
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
453 Y(Y > sz(1)) = 1 + 2*sz(1) - Y(Y > sz(1));
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
454 X(X < 1) = 1 - X(X < 1);
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
455 while (any (X(:) > 2*sz(2)))
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
456 X(X > 2 * sz(2)) = round (X(X > 2*sz(2)) / 2);
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
457 endwhile
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
458 X(X > sz(2)) = 1 + 2*sz(2) - X(X > sz(2));
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
459 ind = sub2ind (sz, Y, X);
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
460 endfunction
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
461
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
462
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
463 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
464 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
465 %! 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
466 %! 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
467 %! 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
468 %! 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
469 %! 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
470 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "linear"));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
471 %! [x,y] = meshgrid (x,y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
472 %! hold on; plot3 (x,y,A,"b*"); hold off;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
473
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
474 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
475 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
476 %! 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
477 %! [x,y,A] = peaks (10);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
478 %! x = x(1,:)'; y = y(:,1);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
479 %! xi = linspace (min (x), max (x), 41);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
480 %! yi = linspace (min (y), max (y), 41)';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
481 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "linear"));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
482 %! [x,y] = meshgrid (x,y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
483 %! hold on; plot3 (x,y,A,"b*"); hold off;
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
484
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
485 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
486 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
487 %! 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
488 %! 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
489 %! 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
490 %! 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
491 %! 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
492 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "nearest"));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
493 %! [x,y] = meshgrid (x,y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
494 %! hold on; plot3 (x,y,A,"b*"); hold off;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
495
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
496 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
497 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
498 %! 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
499 %! [x,y,A] = peaks (10);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
500 %! x = x(1,:)'; y = y(:,1);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
501 %! xi = linspace (min (x), max (x), 41);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
502 %! yi = linspace (min (y), max (y), 41)';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
503 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "nearest"));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
504 %! [x,y] = meshgrid (x,y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
505 %! hold on; plot3 (x,y,A,"b*"); hold off;
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
506
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
507 ## 'pchip' commented out since it is the same as 'cubic'
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
508 %!#demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
509 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
510 %! colormap ("default");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
511 %! A = [13,-1,12;5,4,3;1,6,2];
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
512 %! x = [0,1,2]; y = [10,11,12];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
513 %! xi = linspace (min (x), max (x), 17);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
514 %! yi = linspace (min (y), max (y), 26)';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
515 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "pchip"));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
516 %! [x,y] = meshgrid (x,y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
517 %! hold on; plot3 (x,y,A,"b*"); hold off;
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
518
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
519 ## 'pchip' commented out since it is the same as 'cubic'
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
520 %!#demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
521 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
522 %! 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
523 %! [x,y,A] = peaks (10);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
524 %! x = x(1,:)'; y = y(:,1);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
525 %! xi = linspace (min (x), max (x), 41);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
526 %! yi = linspace (min (y), max (y), 41)';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
527 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "pchip"));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
528 %! [x,y] = meshgrid (x,y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
529 %! hold on; plot3 (x,y,A,"b*"); hold off;
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
530
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
531 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
532 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
533 %! 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
534 %! 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
535 %! 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
536 %! 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
537 %! 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
538 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "cubic"));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
539 %! [x,y] = meshgrid (x,y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
540 %! hold on; plot3 (x,y,A,"b*"); hold off;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
541
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
542 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
543 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
544 %! 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
545 %! [x,y,A] = peaks (10);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
546 %! x = x(1,:)'; y = y(:,1);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
547 %! xi = linspace (min (x), max (x), 41);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
548 %! yi = linspace (min (y), max (y), 41)';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
549 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "cubic"));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
550 %! [x,y] = meshgrid (x,y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
551 %! hold on; plot3 (x,y,A,"b*"); hold off;
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
552
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
553 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
554 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
555 %! 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
556 %! 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
557 %! 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
558 %! 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
559 %! 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
560 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "spline"));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
561 %! [x,y] = meshgrid (x,y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
562 %! hold on; plot3 (x,y,A,"b*"); hold off;
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
563
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
564 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
565 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
566 %! 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
567 %! [x,y,A] = peaks (10);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
568 %! x = x(1,:)'; y = y(:,1);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
569 %! xi = linspace (min (x), max (x), 41);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
570 %! yi = linspace (min (y), max (y), 41)';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
571 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "spline"));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
572 %! [x,y] = meshgrid (x,y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
573 %! hold on; plot3 (x,y,A,"b*"); hold off;
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
574
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
575 %!test # simple test
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
576 %! x = [1,2,3];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
577 %! y = [4,5,6,7];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
578 %! [X, Y] = meshgrid (x, y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
579 %! orig = X.^2 + Y.^3;
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
580 %! xi = [1.2,2, 1.5];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
581 %! yi = [6.2, 4.0, 5.0]';
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
582 %!
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
583 %! expected = ...
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
584 %! [243, 245.4, 243.9;
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
585 %! 65.6, 68, 66.5;
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
586 %! 126.6, 129, 127.5];
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
587 %! result = interp2 (x,y,orig, xi, yi);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
588 %!
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
589 %! assert (result, expected, 1000*eps);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
590
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
591 %!test # 2^n refinement form
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
592 %! x = [1,2,3];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
593 %! y = [4,5,6,7];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
594 %! [X, Y] = meshgrid (x, y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
595 %! orig = X.^2 + Y.^3;
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
596 %! xi = [1:0.25:3]; yi = [4:0.25:7]';
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
597 %! expected = interp2 (x,y,orig, xi, yi);
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
598 %! result = interp2 (orig, 2);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
599 %!
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
600 %! assert (result, expected, 10*eps);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
601
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
602 %!test # matrix slice
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
603 %! A = eye (4);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
604 %! assert (interp2 (A,[1:4],[1:4]), [1,1,1,1]);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
605
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
606 %!test # non-gridded XI,YI
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
607 %! A = eye (4);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
608 %! assert (interp2 (A,[1,2;3,4],[1,3;2,4]), [1,0;0,1]);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
609
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
610 %!test # for values outside of boundaries
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
611 %! x = [1,2,3];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
612 %! y = [4,5,6,7];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
613 %! [X, Y] = meshgrid (x,y);
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
614 %! orig = X.^2 + Y.^3;
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
615 %! xi = [0,4];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
616 %! yi = [3,8]';
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
617 %! assert (interp2 (x,y,orig, xi, yi), [NA,NA;NA,NA]);
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
618 %! assert (interp2 (x,y,orig, xi, yi,"linear", 0), [0,0;0,0]);
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
619 %! assert (interp2 (x,y,orig, xi, yi,"linear", "extrap"), [1,17;468,484]);
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
620 %! assert (interp2 (x,y,orig, xi, yi,"nearest", "extrap"), orig([1,end],[1,end]));
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
621
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
622 %!test # for values at boundaries
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
623 %! A = [1,2;3,4];
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
624 %! x = [0,1];
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
625 %! y = [2,3]';
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
626 %! assert (interp2 (x,y,A,x,y,"linear"), A);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
627 %! assert (interp2 (x,y,A,x,y,"nearest"), A);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
628
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
629 %!test # for Matlab-compatible rounding for 'nearest'
10427
62bb59f927b1 scripts/general/interp2.m, scripts/general/interpn.m: For nearest neighbour interpolation ceil (instead of floor) at the center of the data intervals to be compatible with Matlab. Add test.
Soren Hauberg <hauberg@gmail.com>
parents: 10328
diff changeset
630 %! X = meshgrid (1:4);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
631 %! assert (interp2 (X, 2.5, 2.5, "nearest"), 3);
10427
62bb59f927b1 scripts/general/interp2.m, scripts/general/interpn.m: For nearest neighbour interpolation ceil (instead of floor) at the center of the data intervals to be compatible with Matlab. Add test.
Soren Hauberg <hauberg@gmail.com>
parents: 10328
diff changeset
632
18641
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
633 ## re-order monotonically decreasing (bug #41838).
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
634 %!assert (interp2 ([1 2 3], [3 2 1], magic (3), 2.5, 3), 3.5);
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
635 %!assert (interp2 ([3 2 1], [1 2 3], magic (3), 1.5, 1), 3.5);
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
636
13149
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
637 %!shared z, zout, tol
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
638 %! z = [1 3 5; 3 5 7; 5 7 9];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
639 %! zout = [1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8; 5 6 7 8 9];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
640 %! tol = 2 * eps;
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
641 %!
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
642 %!assert (interp2 (z), zout, tol)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
643 %!assert (interp2 (z, "linear"), zout, tol)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
644 %!assert (interp2 (z, "pchip"), zout, tol)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
645 %!assert (interp2 (z, "cubic"), zout, 10 * tol)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
646 %!assert (interp2 (z, "spline"), zout, tol)
13149
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
647 %!assert (interp2 (z, [2 3 1], [2 2 2]', "linear"), repmat ([5, 7, 3], [3, 1]), tol)
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
648 %!assert (interp2 (z, [2 3 1], [2 2 2]', "pchip"), repmat ([5, 7, 3], [3, 1]), tol)
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
649 %!assert (interp2 (z, [2 3 1], [2 2 2]', "cubic"), repmat ([5, 7, 3], [3, 1]), 10 * tol)
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
650 %!assert (interp2 (z, [2 3 1], [2 2 2]', "spline"), repmat ([5, 7, 3], [3, 1]), tol)
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
651 %!assert (interp2 (z, [2 3 1], [2 2 2], "linear"), [5 7 3], tol)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
652 %!assert (interp2 (z, [2 3 1], [2 2 2], "pchip"), [5 7 3], tol)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
653 %!assert (interp2 (z, [2 3 1], [2 2 2], "cubic"), [5 7 3], 10 * tol)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
654 %!assert (interp2 (z, [2 3 1], [2 2 2], "spline"), [5 7 3], tol)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
655
18587
5cf9a02732b6 Issue warning when '*' flag used with interp2,3,n.m (bug #41459).
Rik <rik@octave.org>
parents: 17744
diff changeset
656 %% Test input validation
18664
900b524d9072 interp2: Verify Z matrix is 2-D (bug #41267).
Rik <rik@octave.org>
parents: 18641
diff changeset
657 %!error <Z must be a 2-D matrix> interp2 ({1})
900b524d9072 interp2: Verify Z matrix is 2-D (bug #41267).
Rik <rik@octave.org>
parents: 18641
diff changeset
658 %!error <Z must be a 2-D matrix> interp2 (ones (2,2,2))
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
659 %!error <N must be an integer .= 0> interp2 (1, ones (2))
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
660 %!error <N must be an integer .= 0> interp2 (1, -1)
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
661 %!error <N must be an integer .= 0> interp2 (1, 1.5)
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
662 %!error <METHOD must be a string> interp2 (1, 1, 1, 1, 1, 2)
18641
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
663 %!warning <ignoring unsupported '\*' flag> interp2 (rand (3,3), 1, "*linear");
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
664 %!error <EXTRAP must be a numeric scalar or "extrap"> interp2 (1, 1, 1, 1, 1, 'linear', {1})
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
665 %!error <EXTRAP must be a numeric scalar or "extrap"> interp2 (1, 1, 1, 1, 1, 'linear', ones (2,2))
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
666 %!error <EXTRAP must be a numeric scalar or "extrap"> interp2 (1, 1, 1, 1, 1, 'linear', "abc")
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
667 %!error <X, Y must be numeric matrices> interp2 ({1}, 1, 1, 1, 1)
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
668 %!error <X, Y must be numeric matrices> interp2 (1, {1}, 1, 1, 1)
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
669 %!error <XI, YI must be numeric> interp2 (1, 1, 1, {1}, 1)
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
670 %!error <XI, YI must be numeric> interp2 (1, 1, 1, 1, {1})
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
671 %!error <X and Y must be matrices of equal size> interp2 (ones(2,2), 1, 1, 1, 1)
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
672 %!error <X and Y must be matrices of equal size> interp2 (ones(2,2), ones(2,3), 1, 1, 1)
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
673 %!error <X and Y size must match the dimensions of Z> interp2 (1:3, 1:3, ones (3,2), 1, 1)
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
674 %!error <X and Y size must match the dimensions of Z> interp2 (1:2, 1:2, ones (3,2), 1, 1)
18641
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
675 %!error <X must be strictly monotonic> interp2 ([1 0 2], 1:3, ones (3,3), 1, 1)
4792a115c735 interp2.m: Add input validation for strictly monotonic x,y (bug #41838).
Rik <rik@octave.org>
parents: 18606
diff changeset
676 %!error <Y must be strictly monotonic> interp2 (1:3, [1 0 2], ones (3,3), 1, 1)
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
677 %!error <XI and YI must be matrices of equal size> interp2 (1, 1, 1, ones(2,2), 1)
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
678 %!error <XI and YI must be matrices of equal size> interp2 (1, 1, 1, 1, ones(2,2))
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
679 %!error <pchip requires at least 2 points> interp2 (1, 1, 1, 1, 1, "pchip")
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
680 %!error <cubic requires at least 2 points> interp2 (1, 1, 1, 1, 1, "cubic")
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
681 %!error <XI, YI must have uniform spacing> interp2 (1, 1, 1, [1 2 4], [1 2 3], "spline")
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
682 %!error <XI, YI must have uniform spacing> interp2 (1, 1, 1, [1 2 3], [1 2 4], "spline")
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18587
diff changeset
683 %!error <unrecognized interpolation method 'foobar'> interp2 (1, 1, 1, 1, 1, "foobar")
18587
5cf9a02732b6 Issue warning when '*' flag used with interp2,3,n.m (bug #41459).
Rik <rik@octave.org>
parents: 17744
diff changeset
684