Mercurial > hg > octave-nkf
annotate scripts/plot/contourc.m @ 16814:64e7bb01fce2
doc: Improve documentation for 2-D plot functions
* doc/interpreter/plot.txi: Rewrite documentation around get/set.
* libinterp/interpfcn/graphics.cc(Fget, Fset): Add seealso links. Add
additional calling forms for get().
* scripts/plot/bar.m, scripts/plot/barh.m, scripts/plot/comet.m,
scripts/plot/comet3.m, scripts/plot/contour.m, scripts/plot/contour3.m,
scripts/plot/contourc.m, scripts/plot/contourf.m, scripts/plot/errorbar.m,
scripts/plot/gca.m, scripts/plot/gcf.m, scripts/plot/gco.m,
scripts/plot/ishghandle.m, scripts/plot/loglogerr.m, scripts/plot/pareto.m,
scripts/plot/pcolor.m, scripts/plot/pie.m, scripts/plot/pie3.m,
scripts/plot/plotmatrix.m, scripts/plot/plotyy.m, scripts/plot/polar.m,
scripts/plot/quiver.m, scripts/plot/quiver3.m, scripts/plot/rose.m,
scripts/plot/scatter.m, scripts/plot/semilogxerr.m, scripts/plot/semilogyerr.m,
scripts/plot/sombrero.m, scripts/plot/stairs.m, scripts/plot/stem.m,
scripts/plot/stem3.m: Improve docstrings.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 22 Jun 2013 17:40:52 -0700 |
parents | c2dbdeaa25df |
children | eaab03308c0b |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
1 ## Copyright (C) 2003-2012 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}) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
24 ## Compute isolines (contour lines) of the matrix @var{z}. |
16814
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
25 ## Parameters @var{x}, @var{y}, and @var{vn} are optional. |
6257 | 26 ## |
27 ## The return value @var{lev} is a vector of the contour levels. | |
16814
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
28 ## The return value @var{c} is a 2x@var{n} matrix containing the |
6257 | 29 ## contour lines in the following format |
30 ## | |
31 ## @example | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
9040
diff
changeset
|
32 ## @group |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
33 ## @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
|
34 ## 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
|
35 ## @end group |
6257 | 36 ## @end example |
37 ## | |
38 ## @noindent | |
39 ## in which contour line @var{n} has a level (height) of @var{levn} and | |
40 ## length of @var{lenn}. | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
41 ## |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
42 ## If @var{x} and @var{y} are omitted they are taken as the row/column |
16814
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
43 ## indices of @var{z}. @var{vn} is either a scalar denoting the number of |
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
44 ## contour lines to compute or a vector containing the values of the lines. |
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
45 ## If only one value is desired, set @code{@var{vn} = [val, val]}; |
6257 | 46 ## If @var{vn} is omitted it defaults to 10. |
47 ## | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
48 ## For example: |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
49 ## |
6257 | 50 ## @example |
6592 | 51 ## @group |
52 ## x = 0:2; | |
53 ## y = x; | |
54 ## z = x' * y; | |
55 ## 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
|
56 ## @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
|
57 ## 2.0000 1.0000 2.0000 2.0000 2.0000 1.5000 |
6592 | 58 ## @end group |
6257 | 59 ## @end example |
16814
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
60 ## @seealso{contour, contourf, contour3} |
6257 | 61 ## @end deftypefn |
62 | |
7327 | 63 ## Author: Shai Ayal <shaiay@users.sourceforge.net> |
6257 | 64 |
8236 | 65 function [cout, lev] = contourc (varargin) |
6257 | 66 |
67 if (nargin == 1) | |
68 vn = 10; | |
69 z = varargin{1}; | |
11499
8f23b6757225
Correction to contourc.m
Michael Godfrey <godfrey@isl.stanford.edu>
parents:
11472
diff
changeset
|
70 [nr, nc] = size (z); |
8f23b6757225
Correction to contourc.m
Michael Godfrey <godfrey@isl.stanford.edu>
parents:
11472
diff
changeset
|
71 x = 1:nc; |
8f23b6757225
Correction to contourc.m
Michael Godfrey <godfrey@isl.stanford.edu>
parents:
11472
diff
changeset
|
72 y = 1:nr; |
6257 | 73 elseif (nargin == 2) |
74 vn = varargin{2}; | |
75 z = varargin{1}; | |
7327 | 76 [nr, nc] = size (z); |
77 x = 1:nc; | |
78 y = 1:nr; | |
6257 | 79 elseif (nargin == 3) |
80 vn = 10; | |
81 x = varargin{1}; | |
82 y = varargin{2}; | |
83 z = varargin{3}; | |
84 elseif (nargin == 4) | |
85 vn = varargin{4}; | |
86 x = varargin{1}; | |
87 y = varargin{2}; | |
88 z = varargin{3}; | |
89 else | |
90 print_usage (); | |
91 endif | |
92 | |
10634
60542efcfa2c
Check input arguments for size and type (bug #29861).
Rik <octave@nomad.inbox5.com>
parents:
9758
diff
changeset
|
93 if (!ismatrix (z) || isvector (z) || isscalar (z)) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
94 error ("contourc: Z argument must be a matrix"); |
10634
60542efcfa2c
Check input arguments for size and type (bug #29861).
Rik <octave@nomad.inbox5.com>
parents:
9758
diff
changeset
|
95 endif |
60542efcfa2c
Check input arguments for size and type (bug #29861).
Rik <octave@nomad.inbox5.com>
parents:
9758
diff
changeset
|
96 |
6257 | 97 if (isscalar (vn)) |
98 vv = linspace (min (z(:)), max (z(:)), vn+2)(2:end-1); | |
99 else | |
100 vv = unique (sort (vn)); | |
101 endif | |
102 | |
7327 | 103 if (isvector (x) && isvector (y)) |
104 c = __contourc__ (x(:)', y(:)', z, vv); | |
105 else | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
106 ## Indexes x,y for the purpose of __contourc__. |
14872
c2dbdeaa25df
maint: use rows() and columns() to clarify m-files.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
107 ii = 1:columns (z); |
c2dbdeaa25df
maint: use rows() and columns() to clarify m-files.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
108 jj = 1:rows (z); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
109 |
7327 | 110 ## Now call __contourc__ for the real work... |
111 c = __contourc__ (ii, jj, z, vv); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
112 |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
113 ## Map the contour lines from index space (i,j) back |
7327 | 114 ## to the original grid (x,y) |
115 i = 1; | |
6257 | 116 |
14872
c2dbdeaa25df
maint: use rows() and columns() to clarify m-files.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
117 while (i < columns (c)) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
118 clen = c(2, i); |
7327 | 119 ind = i + [1 : clen]; |
6257 | 120 |
7327 | 121 ci = c(1, ind); |
122 cj = c(2,ind); | |
123 | |
124 ## due to rounding errors some elements of ci and cj | |
125 ## can fall out of the range of ii and jj and interp2 would | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
126 ## return NA for those values. |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
127 ## 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
|
128 |
14872
c2dbdeaa25df
maint: use rows() and columns() to clarify m-files.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
129 ci = max (ci, 1); ci = min (ci, columns (z)); |
c2dbdeaa25df
maint: use rows() and columns() to clarify m-files.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
130 cj = max (cj, 1); cj = min (cj, rows (z)); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
131 |
7327 | 132 c(1, ind) = interp2 (ii, jj, x, ci, cj); |
133 c(2, ind) = 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
|
134 |
7327 | 135 i = i + clen + 1; |
136 endwhile | |
6257 | 137 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
138 |
8236 | 139 if (nargout > 0) |
140 cout = c; | |
6257 | 141 lev = vv; |
142 endif | |
143 | |
144 endfunction | |
7245 | 145 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
146 |
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
|
147 %!test |
7245 | 148 %! x = 0:2; |
149 %! y = x; | |
150 %! z = x' * y; | |
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
|
151 %! [c_actual, lev_actual]= contourc (x, y, z, 2:3); |
a013ff655ca4
Trivial changes to demos to produce a more pleasant output for octave+gnuplot+aquaterm.
Ben Abbott <bpabbott@mac.com>
parents:
8325
diff
changeset
|
152 %! c_expected = [2, 1, 1, 2, 2, 3, 1.5, 2; 4, 2, 2, 1, 1, 2, 2, 1.5]; |
a013ff655ca4
Trivial changes to demos to produce a more pleasant output for octave+gnuplot+aquaterm.
Ben Abbott <bpabbott@mac.com>
parents:
8325
diff
changeset
|
153 %! lev_expected = [2 3]; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
154 %! assert (c_actual, c_expected, eps); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
155 %! assert (lev_actual, lev_expected, 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
|
156 |