annotate scripts/deprecated/bicubic.m @ 20595:c1a6c31ac29a

eliminate more simple uses of error_state * ov-classdef.cc: Eliminate simple uses of error_state.
author John W. Eaton <jwe@octave.org>
date Tue, 06 Oct 2015 00:20:02 -0400
parents 4197fc428c7d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19679
diff changeset
1 ## Copyright (C) 2005-2015 Hoxide Ma
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
2 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
4 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
5 ## 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
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6702
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6702
diff changeset
8 ## your option) any later version.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
9 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
10 ## 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
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
14 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6702
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6702
diff changeset
17 ## <http://www.gnu.org/licenses/>.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
18
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
20 ## @deftypefn {Function File} {@var{zi} =} bicubic (@var{x}, @var{y}, @var{z}, @var{xi}, @var{yi}, @var{extrapval})
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
21 ##
19679
ebd27d8c63fd update default branch to release as 4.0
John W. Eaton <jwe@octave.org>
parents: 18683
diff changeset
22 ## @code{bicubic} is deprecated and will be removed in Octave version 4.4.
18683
7485f8a8e431 bicubic.m: Deprecate function for 4.2 release.
Rik <rik@octave.org>
parents: 18640
diff changeset
23 ## Use @code{interp2 (@dots{}, "spline")} for the equivalent functionality.
7485f8a8e431 bicubic.m: Deprecate function for 4.2 release.
Rik <rik@octave.org>
parents: 18640
diff changeset
24 ##
6653
673686daec87 [project @ 2007-05-22 15:36:09 by jwe]
jwe
parents: 6448
diff changeset
25 ## Return a matrix @var{zi} corresponding to the bicubic
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
26 ## interpolations at @var{xi} and @var{yi} of the data supplied
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
27 ## as @var{x}, @var{y} and @var{z}. Points outside the grid are set
8828
8463d1a2e544 Doc fixes.
Brian Gough <bjg@network-theory.co.uk>
parents: 8507
diff changeset
28 ## to @var{extrapval}.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
29 ##
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6653
diff changeset
30 ## See @url{http://wiki.woodpecker.org.cn/moin/Octave/Bicubic}
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6653
diff changeset
31 ## for further information.
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
32 ## @seealso{interp2}
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
33 ## @end deftypefn
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
34
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
35 ## Bicubic interpolation method.
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
36 ## Author: Hoxide Ma <hoxide_dirac@yahoo.com.cn>
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
37
19679
ebd27d8c63fd update default branch to release as 4.0
John W. Eaton <jwe@octave.org>
parents: 18683
diff changeset
38 ## Deprecated in version 4.0
18683
7485f8a8e431 bicubic.m: Deprecate function for 4.2 release.
Rik <rik@octave.org>
parents: 18640
diff changeset
39
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
40 function zi = bicubic (x, y, z, xi, yi, extrapval, spline_alpha)
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
41
18683
7485f8a8e431 bicubic.m: Deprecate function for 4.2 release.
Rik <rik@octave.org>
parents: 18640
diff changeset
42 persistent warned = false;
7485f8a8e431 bicubic.m: Deprecate function for 4.2 release.
Rik <rik@octave.org>
parents: 18640
diff changeset
43 if (! warned)
7485f8a8e431 bicubic.m: Deprecate function for 4.2 release.
Rik <rik@octave.org>
parents: 18640
diff changeset
44 warned = true;
7485f8a8e431 bicubic.m: Deprecate function for 4.2 release.
Rik <rik@octave.org>
parents: 18640
diff changeset
45 warning ("Octave:deprecated-function",
7485f8a8e431 bicubic.m: Deprecate function for 4.2 release.
Rik <rik@octave.org>
parents: 18640
diff changeset
46 "bicubic is obsolete and will be removed from a future version of Octave, please use interp2 instead");
7485f8a8e431 bicubic.m: Deprecate function for 4.2 release.
Rik <rik@octave.org>
parents: 18640
diff changeset
47 endif
7485f8a8e431 bicubic.m: Deprecate function for 4.2 release.
Rik <rik@octave.org>
parents: 18640
diff changeset
48
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6653
diff changeset
49 if (nargin < 1 || nargin > 7)
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
50 print_usage ();
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
51 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
52
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14598
diff changeset
53 if (nargin == 7 && isscalar (spline_alpha))
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
54 a = spline_alpha;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
55 else
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
56 a = 0.5;
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
57 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
58
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6653
diff changeset
59 if (nargin < 6)
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6653
diff changeset
60 extrapval = NaN;
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6653
diff changeset
61 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6653
diff changeset
62
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
63 if (isa (x, "single") || isa (y, "single") || isa (z, "single")
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
64 || isa (xi, "single") || isa (yi, "single"))
14598
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
65 myeps = eps ("single");
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
66 else
14598
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
67 myeps = eps ();
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
68 endif
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
69
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
70 if (nargin <= 2)
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
71 ## bicubic (z) or bicubic (z, 2)
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
72 if (nargin == 1)
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
73 n = 1;
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
74 else
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
75 n = y;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
76 endif
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
77 z = x;
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
78 x = [];
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
79 [rz, cz] = size (z);
14598
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
80 s = linspace (1, cz, (cz-1) * pow2 (n) + 1);
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
81 t = linspace (1, rz, (rz-1) * pow2 (n) + 1);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
82 elseif (nargin == 3)
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
83 if (! isvector (x) || ! isvector (y))
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
84 error ("bicubic: XI and YI must be vector");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
85 endif
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
86 s = y;
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
87 t = z;
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
88 z = x;
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
89 [rz, cz] = size (z);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
90 elseif (nargin == 5 || nargin == 6)
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
91 [rz, cz] = size (z) ;
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
92 if (isvector (x) && isvector (y))
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
93 if (rz != length (y) || cz != length (x))
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
94 error ("bicubic: length of X and Y must match the size of Z");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
95 endif
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
96 elseif (size_equal (x, y) && size_equal (x, z))
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
97 x = x(1,:);
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
98 y = y(:,1);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
99 else
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
100 error ("bicubic: X, Y and Z must be equal size matrices of same size");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
101 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
102
14598
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
103 if (all (diff (x) < 0))
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
104 flipx = true;
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
105 x = fliplr (x);
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
106 elseif (all (diff (x) > 0))
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
107 flipx = false;
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
108 else
15202
f3b5cadfd6d5 fix missing semicolons in various .m files
John W. Eaton <jwe@octave.org>
parents: 14868
diff changeset
109 error ("bicubic:nonmonotonic", "bicubic: X values must be monotonic");
14598
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
110 endif
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
111 if (all (diff (y) < 0))
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
112 flipy = true;
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
113 y = flipud (y);
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
114 elseif (all (diff (y) > 0))
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
115 flipy = false;
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
116 else
15202
f3b5cadfd6d5 fix missing semicolons in various .m files
John W. Eaton <jwe@octave.org>
parents: 14868
diff changeset
117 error ("bicubic:nonmonotonic", "bicubic: Y values must be monotonic");
14598
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
118 endif
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
119
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7795
diff changeset
120 ## Mark values outside the lookup table.
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
121 xfirst_ind = find (xi < x(1));
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
122 xlast_ind = find (xi > x(cz));
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
123 yfirst_ind = find (yi < y(1));
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
124 ylast_ind = find (yi > y(rz));
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7795
diff changeset
125 ## Set value outside the table preliminary to min max index.
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
126 xi(xfirst_ind) = x(1);
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
127 xi(xlast_ind) = x(cz);
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
128 yi(yfirst_ind) = y(1);
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
129 yi(ylast_ind) = y(rz);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
130
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
131 x = reshape (x, 1, cz);
14598
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
132 x(cz) *= 1 + sign (x(cz)) * myeps;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
133 if (x(cz) == 0)
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
134 x(cz) = myeps;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
135 endif;
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
136 xi = reshape (xi, 1, length (xi));
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
137 [m, i] = sort ([x, xi]);
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
138 o = cumsum (i <= cz);
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
139 xidx = o(find (i > cz));
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
140
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
141 y = reshape (y, rz, 1);
14598
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
142 y(rz) *= 1 + sign (y(rz)) * myeps;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
143 if (y(rz) == 0)
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
144 y(rz) = myeps;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
145 endif;
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
146 yi = reshape (yi, length (yi), 1);
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
147 [m, i] = sort ([y; yi]);
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
148 o = cumsum (i <= rz);
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
149 yidx = o([find(i > rz)]);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
150
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7795
diff changeset
151 ## Set s and t used follow codes.
14598
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
152 s = xidx + ((xi .- x(xidx)) ./ (x(xidx+1) .- x(xidx)));
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
153 t = yidx + ((yi - y(yidx)) ./ (y(yidx+1) - y(yidx)));
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
154
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
155 if (flipx)
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
156 s = fliplr (s);
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
157 endif
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
158 if (flipy)
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
159 t = flipud (t);
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
160 endif
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
161 else
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
162 print_usage ();
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
163 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
164
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
165 if (rz < 3 || cz < 3)
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
166 error ("bicubic: Z at least a 3 by 3 matrices");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
167 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
168
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
169 inds = floor (s);
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
170 d = find (s == cz);
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
171 s = s - floor (s);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
172 inds(d) = cz-1;
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
173 s(d) = 1.0;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
174
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
175 d = [];
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
176 indt = floor (t);
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
177 d = find (t == rz);
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
178 t = t - floor (t);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
179 indt(d) = rz-1;
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
180 t(d) = 1.0;
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
181 d = [];
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
182
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
183 p = zeros (size (z) + 2);
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
184 p(2:rz+1,2:cz+1) = z;
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
185 p(1,:) = (6*(1-a))*p(2,:) - 3*p(3,:) + (6*a-2)*p(4,:);
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
186 p(rz+2,:) = (6*(1-a))*p(rz+1,:) - 3*p(rz,:) + (6*a-2)*p(rz-1,:);
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
187 p(:,1) = (6*(1-a))*p(:,2) - 3*p(:,3) + (6*a-2)*p(:,4);
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
188 p(:,cz+2) = (6*(1-a))*p(:,cz+1) - 3*p(:,cz) + (6*a-2)*p(:,cz-1);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
189
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7795
diff changeset
190 ## Calculte the C1(t) C2(t) C3(t) C4(t) and C1(s) C2(s) C3(s) C4(s).
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
191 t2 = t.*t;
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
192 t3 = t2.*t;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
193
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
194 ct0 = -a .* t3 + (2 * a) .* t2 - a .* t ; # -a G0
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
195 ct1 = (2-a) .* t3 + (-3+a) .* t2 + 1 ; # F0 - a G1
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
196 ct2 = (a-2) .* t3 + (-2 *a + 3) .* t2 + a .* t ; # F1 + a G0
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
197 ct3 = a .* t3 - a .* t2; # a G1
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
198 t = []; t2 = []; t3 = [];
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
199
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
200 s2 = s.*s;
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
201 s3 = s2.*s;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
202
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
203 cs0 = -a .* s3 + (2 * a) .* s2 - a .*s ; # -a G0
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
204 cs1 = (2-a) .* s3 + (-3 + a) .* s2 + 1 ; # F0 - a G1
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
205 cs2 = (a-2) .* s3 + (-2 *a + 3) .* s2 + a .*s ; # F1 + a G0
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
206 cs3 = a .* s3 - a .* s2; # a G1
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
207 s = []; s2 = []; s3 = [];
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
208
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
209 cs0 = cs0([1,1,1,1],:);
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
210 cs1 = cs1([1,1,1,1],:);
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
211 cs2 = cs2([1,1,1,1],:);
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
212 cs3 = cs3([1,1,1,1],:);
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
213
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
214 lent = length (ct0);
10859
09144fbb0e36 Fix bug #30400 when bicubic called with small numbers of arguments.
Rik <octave@nomad.inbox5.com>
parents: 10635
diff changeset
215 lens = columns (cs0);
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
216 zi = zeros (lent, lens);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
217
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
218 for i = 1:lent
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
219 it = indt(i);
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
220 int = [it, it+1, it+2, it+3];
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
221 zi(i,:) = ([ct0(i),ct1(i),ct2(i),ct3(i)]
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
222 * (p(int,inds) .* cs0 + p(int,inds+1) .* cs1
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
223 + p(int,inds+2) .* cs2 + p(int,inds+3) .* cs3));
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
224 endfor
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
225
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7795
diff changeset
226 ## Set points outside the table to extrapval.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
227 if (! (isempty (xfirst_ind) && isempty (xlast_ind)))
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
228 zi(:, [xfirst_ind, xlast_ind]) = extrapval;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
229 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
230 if (! (isempty (yfirst_ind) && isempty (ylast_ind)))
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
231 zi([yfirst_ind; ylast_ind], :) = extrapval;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
232 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
233
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
234 endfunction
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
235
17338
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 15202
diff changeset
236
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
237 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
238 %! clf;
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
239 %! 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
240 %! A = [13,-1,12;5,4,3;1,6,2];
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
241 %! x = [0,1,4]+10;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
242 %! y = [-10,-9,-8];
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
243 %! xi = linspace (min (x), max (x), 17);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
244 %! yi = linspace (min (y), max (y), 26)';
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
245 %! mesh (xi, yi, bicubic (x,y,A,xi,yi));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
246 %! [x,y] = meshgrid (x,y);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
247 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
248
14598
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
249 %!test
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
250 %! x = linspace (1, -1, 10);
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
251 %! [xx, yy] = meshgrid (x);
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
252 %! z = cos (6 * xx) + sin (6 * yy);
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
253 %! x = linspace (1, -1, 30);
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
254 %! [xx2, yy2] = meshgrid (x);
18640
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 17744
diff changeset
255 %! z1 = interp2 (xx, yy, z, xx2, yy2, "spline");
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14598
diff changeset
256 %! z2 = interp2 (fliplr (xx), flipud (yy), fliplr (flipud(z)),
18640
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 17744
diff changeset
257 %! fliplr (xx2), flipud (yy2), "spline");
14598
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
258 %! z2 = fliplr (flipud (z2));
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
259 %! assert (z1, z2, 100 * eps ())
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
260