Mercurial > hg > octave-nkf
annotate scripts/plot/draw/contourc.m @ 20177:15e5eb7a0c1d
make dist: add updated zoom images to EXTRADIST (bug #44579)
* libgui/graphics/module.mk: add graphics/images/zoom-in.png, graphics/images/zoom-out.png, remove graphics/images/zoom.png
author | John Donoghue |
---|---|
date | Thu, 19 Mar 2015 08:37:47 -0400 |
parents | 4197fc428c7d |
children | 4e7f12a763cd |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1 ## Copyright (C) 2003-2015 Shai Ayal |
6257 | 2 ## |
6440 | 3 ## This file is part of Octave. |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6257 | 6 ## under the terms of the GNU General Public License as published by |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
6257 | 9 ## |
6440 | 10 ## Octave is distributed in the hope that it will be useful, but |
6257 | 11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
6257 | 18 |
19 ## -*- texinfo -*- | |
16814
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
20 ## @deftypefn {Function File} {[@var{c}, @var{lev}] =} contourc (@var{z}) |
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
21 ## @deftypefnx {Function File} {[@var{c}, @var{lev}] =} contourc (@var{z}, @var{vn}) |
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
22 ## @deftypefnx {Function File} {[@var{c}, @var{lev}] =} contourc (@var{x}, @var{y}, @var{z}) |
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
23 ## @deftypefnx {Function File} {[@var{c}, @var{lev}] =} contourc (@var{x}, @var{y}, @var{z}, @var{vn}) |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
24 ## Compute contour lines (isolines of constant Z value). |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
25 ## |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
26 ## The matrix @var{z} contains height values above the rectangular grid |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
27 ## determined by @var{x} and @var{y}. If only a single input @var{z} is |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
28 ## provided then @var{x} is taken to be @code{1:rows (@var{z})} and @var{y} is |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
29 ## taken to be @code{1:columns (@var{z})}. |
6257 | 30 ## |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
31 ## The optional input @var{vn} is either a scalar denoting the number of |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
32 ## contour lines to compute or a vector containing the Z values where lines |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
33 ## will be computed. When @var{vn} is a vector the number of contour lines |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
34 ## is @code{numel (@var{vn})}. However, to compute a single contour line |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
35 ## at a given value use @code{@var{vn} = [val, val]}. If @var{vn} is omitted |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
36 ## it defaults to 10. |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
37 ## |
16814
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
38 ## The return value @var{c} is a 2x@var{n} matrix containing the |
6257 | 39 ## contour lines in the following format |
40 ## | |
41 ## @example | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
9040
diff
changeset
|
42 ## @group |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
43 ## @var{c} = [lev1, x1, x2, @dots{}, levn, x1, x2, ... |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
44 ## len1, y1, y2, @dots{}, lenn, y1, y2, @dots{}] |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
9040
diff
changeset
|
45 ## @end group |
6257 | 46 ## @end example |
47 ## | |
48 ## @noindent | |
49 ## in which contour line @var{n} has a level (height) of @var{levn} and | |
50 ## length of @var{lenn}. | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
51 ## |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
52 ## The optional return value @var{lev} is a vector with the Z values of |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
53 ## of the contour levels. |
6257 | 54 ## |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
55 ## Example: |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
56 ## |
6257 | 57 ## @example |
6592 | 58 ## @group |
59 ## x = 0:2; | |
60 ## y = x; | |
61 ## z = x' * y; | |
62 ## contourc (x, y, z, 2:3) | |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
63 ## @result{} 2.0000 2.0000 1.0000 3.0000 1.5000 2.0000 |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
64 ## 2.0000 1.0000 2.0000 2.0000 2.0000 1.5000 |
6592 | 65 ## @end group |
6257 | 66 ## @end example |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
67 ## @seealso{contour, contourf, contour3, clabel} |
6257 | 68 ## @end deftypefn |
69 | |
7327 | 70 ## Author: Shai Ayal <shaiay@users.sourceforge.net> |
6257 | 71 |
17451
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
72 function [c, lev] = contourc (varargin) |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
73 |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
74 if (nargin < 1 || nargin > 4) |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
75 print_usage (); |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
76 endif |
6257 | 77 |
78 if (nargin == 1) | |
79 z = varargin{1}; | |
17451
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
80 x = 1:columns (z); |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
81 y = 1:rows (z); |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
82 vn = 10; |
6257 | 83 elseif (nargin == 2) |
17451
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
84 z = varargin{1}; |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
85 x = 1:columns (z); |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
86 y = 1:rows (z); |
6257 | 87 vn = varargin{2}; |
88 elseif (nargin == 3) | |
89 x = varargin{1}; | |
90 y = varargin{2}; | |
91 z = varargin{3}; | |
17451
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
92 vn = 10; |
6257 | 93 elseif (nargin == 4) |
94 x = varargin{1}; | |
95 y = varargin{2}; | |
96 z = varargin{3}; | |
17451
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
97 vn = varargin{4}; |
6257 | 98 endif |
99 | |
17451
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
100 if (! ismatrix (z) || ! ismatrix (x) || ! ismatrix (y)) |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
101 error ("contourc: X, Y, and Z must be matrices"); |
10634
60542efcfa2c
Check input arguments for size and type (bug #29861).
Rik <octave@nomad.inbox5.com>
parents:
9758
diff
changeset
|
102 endif |
60542efcfa2c
Check input arguments for size and type (bug #29861).
Rik <octave@nomad.inbox5.com>
parents:
9758
diff
changeset
|
103 |
6257 | 104 if (isscalar (vn)) |
105 vv = linspace (min (z(:)), max (z(:)), vn+2)(2:end-1); | |
106 else | |
107 vv = unique (sort (vn)); | |
108 endif | |
109 | |
7327 | 110 if (isvector (x) && isvector (y)) |
17451
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
111 cdat = __contourc__ (x(:)', y(:)', z, vv); |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
112 elseif (! any (bsxfun (@minus, x, x(1,:))(:)) |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
113 && ! any (bsxfun (@minus, y, y(:,1))(:))) |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
114 ## x,y are uniform grid (such as from meshgrid) |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
115 cdat = __contourc__ (x(1,:), y(:,1)', z, vv); |
7327 | 116 else |
17451
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
117 ## Data is sampled over non-uniform mesh. |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
118 ## Algorithm calculates contours for uniform grid |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
119 ## and then interpolates values back to the non-uniform mesh. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
120 |
17451
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
121 ## Uniform grid for __contourc__. |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
122 [nr, nc] = size (z); |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
123 ii = 1:nc; |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
124 jj = 1:nr; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
125 |
17451
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
126 cdat = __contourc__ (ii, jj, z, vv); |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
127 |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
128 ## Map the contour lines from index space (i,j) |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
129 ## back to the original grid (x,y) |
7327 | 130 i = 1; |
6257 | 131 |
17451
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
132 while (i < columns (cdat)) |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
133 clen = cdat(2, i); |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
134 idx = i + (1:clen); |
6257 | 135 |
17451
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
136 ci = cdat(1, idx); |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
137 cj = cdat(2, idx); |
7327 | 138 |
17451
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
139 ## Due to rounding errors, some elements of ci and cj |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
140 ## can fall out of the range of ii and jj and |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
141 ## interp2 would return NA for those values. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
142 ## The permitted range is enforced here: |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
143 |
17451
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
144 ci = max (ci, 1); ci = min (ci, nc); |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
145 cj = max (cj, 1); cj = min (cj, nr); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
146 |
17451
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
147 cdat(1, idx) = interp2 (ii, jj, x, ci, cj); |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
148 cdat(2, idx) = interp2 (ii, jj, y, ci, cj); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
149 |
17451
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
150 i += clen + 1; |
7327 | 151 endwhile |
6257 | 152 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
153 |
8236 | 154 if (nargout > 0) |
17451
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
155 c = cdat; |
6257 | 156 lev = vv; |
157 endif | |
158 | |
159 endfunction | |
7245 | 160 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
161 |
8790
a013ff655ca4
Trivial changes to demos to produce a more pleasant output for octave+gnuplot+aquaterm.
Ben Abbott <bpabbott@mac.com>
parents:
8325
diff
changeset
|
162 %!test |
7245 | 163 %! x = 0:2; |
164 %! y = x; | |
165 %! z = x' * y; | |
17451
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
166 %! c_exp = [2, 1, 1, 2, 2, 3, 1.5, 2; 4, 2, 2, 1, 1, 2, 2, 1.5]; |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
167 %! lev_exp = [2 3]; |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
168 %! [c_obs, lev_obs] = contourc (x, y, z, 2:3); |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
169 %! assert (c_obs, c_exp, eps); |
56e72e8d1aba
contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
170 %! assert (lev_obs, lev_exp, eps); |
8790
a013ff655ca4
Trivial changes to demos to produce a more pleasant output for octave+gnuplot+aquaterm.
Ben Abbott <bpabbott@mac.com>
parents:
8325
diff
changeset
|
171 |