annotate scripts/general/bicubic.m @ 15202:f3b5cadfd6d5

fix missing semicolons in various .m files * playaudio.m, accumarray.m, accumdim.m, bicubic.m, narginchk.m, nargoutchk.m, nthargout.m, image.m, pkg.m, colorbar.m, hdl2struct.m, legend.m, plotyy.m, private/__go_draw_axes__.m, private/__print_parse_opts__.m, shrinkfaces.m, pchip.m, polyval.m, rundemos.m: Fix lines with missing semicolons.
author John W. Eaton <jwe@octave.org>
date Sun, 19 Aug 2012 10:50:40 -0400
parents 5d3a684236b0
children 1c89599167a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 11589
diff changeset
1 ## Copyright (C) 2005-2012 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 ##
6653
673686daec87 [project @ 2007-05-22 15:36:09 by jwe]
jwe
parents: 6448
diff changeset
22 ## 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
23 ## 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
24 ## 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
25 ## to @var{extrapval}.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
26 ##
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6653
diff changeset
27 ## 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
28 ## for further information.
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
29 ## @seealso{interp2}
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
30 ## @end deftypefn
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
31
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
32 ## Bicubic interpolation method.
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
33 ## Author: Hoxide Ma <hoxide_dirac@yahoo.com.cn>
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
34
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
35 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
36
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6653
diff changeset
37 if (nargin < 1 || nargin > 7)
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
38 print_usage ();
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
39 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
40
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14598
diff changeset
41 if (nargin == 7 && isscalar (spline_alpha))
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
42 a = spline_alpha;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
43 else
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
44 a = 0.5;
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
45 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
46
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6653
diff changeset
47 if (nargin < 6)
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6653
diff changeset
48 extrapval = NaN;
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6653
diff changeset
49 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6653
diff changeset
50
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
51 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
52 || isa (xi, "single") || isa (yi, "single"))
14598
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
53 myeps = eps ("single");
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
54 else
14598
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
55 myeps = eps ();
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
56 endif
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
57
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
58 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
59 ## 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
60 if (nargin == 1)
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
61 n = 1;
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
62 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
63 n = y;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
64 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
65 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
66 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
67 [rz, cz] = size (z);
14598
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
68 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
69 t = linspace (1, rz, (rz-1) * pow2 (n) + 1);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
70 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
71 if (! isvector (x) || ! isvector (y))
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
72 error ("bicubic: XI and YI must be vector");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
73 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
74 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
75 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
76 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
77 [rz, cz] = size (z);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
78 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
79 [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
80 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
81 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
82 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
83 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
84 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
85 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
86 y = y(:,1);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
87 else
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
88 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
89 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
90
14598
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
91 if (all (diff (x) < 0))
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
92 flipx = true;
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
93 x = fliplr (x);
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
94 elseif (all (diff (x) > 0))
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
95 flipx = false;
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
96 else
15202
f3b5cadfd6d5 fix missing semicolons in various .m files
John W. Eaton <jwe@octave.org>
parents: 14868
diff changeset
97 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
98 endif
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
99 if (all (diff (y) < 0))
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
100 flipy = true;
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
101 y = flipud (y);
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
102 elseif (all (diff (y) > 0))
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
103 flipy = false;
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
104 else
15202
f3b5cadfd6d5 fix missing semicolons in various .m files
John W. Eaton <jwe@octave.org>
parents: 14868
diff changeset
105 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
106 endif
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
107
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7795
diff changeset
108 ## 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
109 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
110 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
111 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
112 ylast_ind = find (yi > y(rz));
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7795
diff changeset
113 ## 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
114 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
115 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
116 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
117 yi(ylast_ind) = y(rz);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
118
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
119 x = reshape (x, 1, cz);
14598
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
120 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
121 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
122 x(cz) = myeps;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
123 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
124 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
125 [m, i] = sort ([x, xi]);
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
126 o = cumsum (i <= cz);
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
127 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
128
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
129 y = reshape (y, rz, 1);
14598
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
130 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
131 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
132 y(rz) = myeps;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
133 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
134 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
135 [m, i] = sort ([y; yi]);
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
136 o = cumsum (i <= rz);
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
137 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
138
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7795
diff changeset
139 ## Set s and t used follow codes.
14598
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
140 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
141 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
142
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
143 if (flipx)
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
144 s = fliplr (s);
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
145 endif
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
146 if (flipy)
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
147 t = flipud (t);
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
148 endif
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
149 else
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
150 print_usage ();
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
151 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
152
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
153 if (rz < 3 || cz < 3)
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
154 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
155 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
156
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
157 inds = floor (s);
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
158 d = find (s == cz);
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
159 s = s - floor (s);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
160 inds(d) = cz-1;
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
161 s(d) = 1.0;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
162
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
163 d = [];
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
164 indt = floor (t);
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
165 d = find (t == rz);
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
166 t = t - floor (t);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
167 indt(d) = rz-1;
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
168 t(d) = 1.0;
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
169 d = [];
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
170
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
171 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
172 p(2:rz+1,2:cz+1) = z;
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
173 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
174 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
175 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
176 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
177
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7795
diff changeset
178 ## 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
179 t2 = t.*t;
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
180 t3 = t2.*t;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
181
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
182 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
183 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
184 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
185 ct3 = a .* t3 - a .* t2; # a G1
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
186 t = []; t2 = []; t3 = [];
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
187
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
188 s2 = s.*s;
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
189 s3 = s2.*s;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
190
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
191 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
192 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
193 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
194 cs3 = a .* s3 - a .* s2; # a G1
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
195 s = []; s2 = []; s3 = [];
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
196
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
197 cs0 = cs0([1,1,1,1],:);
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
198 cs1 = cs1([1,1,1,1],:);
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
199 cs2 = cs2([1,1,1,1],:);
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
200 cs3 = cs3([1,1,1,1],:);
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
201
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
202 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
203 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
204 zi = zeros (lent, lens);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
205
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
206 for i = 1:lent
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
207 it = indt(i);
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
208 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
209 zi(i,:) = ([ct0(i),ct1(i),ct2(i),ct3(i)]
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
210 * (p(int,inds) .* cs0 + p(int,inds+1) .* cs1
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
211 + 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
212 endfor
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
213
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7795
diff changeset
214 ## Set points outside the table to extrapval.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
215 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
216 zi(:, [xfirst_ind, xlast_ind]) = extrapval;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
217 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
218 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
219 zi([yfirst_ind; ylast_ind], :) = extrapval;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
220 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
221
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
222 endfunction
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
223
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
224 %!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
225 %! 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
226 %! 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
227 %! 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
228 %! 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
229 %! 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
230 %! 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
231 %! 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
232 %! 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
233 %! [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
234 %! 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
235
14598
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
236 %!test
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
237 %! x = linspace (1, -1, 10);
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
238 %! [xx, yy] = meshgrid (x);
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
239 %! z = cos (6 * xx) + sin (6 * yy);
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
240 %! x = linspace (1, -1, 30);
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
241 %! [xx2, yy2] = meshgrid (x);
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
242 %! z1 = interp2 (xx, yy, z, xx2, yy2, "cubic");
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14598
diff changeset
243 %! z2 = interp2 (fliplr (xx), flipud (yy), fliplr (flipud(z)),
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14598
diff changeset
244 %! fliplr (xx2), flipud (yy2), "cubic");
14598
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
245 %! z2 = fliplr (flipud (z2));
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
246 %! assert (z1, z2, 100 * eps ())
0d37fda09415 Allow monotonically decending inputs to bicubic ().
Ben Abbott <bpabbott@mac.com>
parents: 14247
diff changeset
247