Mercurial > hg > octave-lyh
annotate scripts/plot/contourc.m @ 11366:ad8966096e27
bar.m: Improve the docstring.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Tue, 14 Dec 2010 18:40:38 -0800 |
parents | a4f482e66b65 |
children | 1740012184f9 |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2003, 2007, 2008, 2009 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 -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10634
diff
changeset
|
20 ## @deftypefn {Function File} {[@var{c}, @var{lev}] =} contourc (@var{x}, @var{y}, @var{z}, @var{vn}) |
8325
b93ac0586e4b
spelling corrections
Brian Gough<bjg@network-theory.co.uk>
parents:
8236
diff
changeset
|
21 ## Compute isolines (contour lines) of the matrix @var{z}. |
6257 | 22 ## Parameters @var{x}, @var{y} and @var{vn} are optional. |
23 ## | |
24 ## The return value @var{lev} is a vector of the contour levels. | |
25 ## The return value @var{c} is a 2 by @var{n} matrix containing the | |
26 ## contour lines in the following format | |
27 ## | |
28 ## @example | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
9040
diff
changeset
|
29 ## @group |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
30 ## @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
|
31 ## 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
|
32 ## @end group |
6257 | 33 ## @end example |
34 ## | |
35 ## @noindent | |
36 ## in which contour line @var{n} has a level (height) of @var{levn} and | |
37 ## length of @var{lenn}. | |
38 ## | |
39 ## If @var{x} and @var{y} are omitted they are taken as the row/column | |
40 ## index of @var{z}. @var{vn} is either a scalar denoting the number of lines | |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
41 ## to compute or a vector containing the values of the lines. If only one |
6257 | 42 ## value is wanted, set @code{@var{vn} = [val, val]}; |
43 ## If @var{vn} is omitted it defaults to 10. | |
44 ## | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
45 ## For example: |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
46 ## |
6257 | 47 ## @example |
6592 | 48 ## @group |
49 ## x = 0:2; | |
50 ## y = x; | |
51 ## z = x' * y; | |
52 ## contourc (x, y, z, 2:3) | |
53 ## @result{} 2.0000 2.0000 1.0000 3.0000 1.5000 2.0000 | |
54 ## 2.0000 1.0000 2.0000 2.0000 2.0000 1.5000 | |
55 ## | |
56 ## @end group | |
6257 | 57 ## @end example |
58 ## @seealso{contour} | |
59 ## @end deftypefn | |
60 | |
7327 | 61 ## Author: Shai Ayal <shaiay@users.sourceforge.net> |
6257 | 62 |
8236 | 63 function [cout, lev] = contourc (varargin) |
6257 | 64 |
65 if (nargin == 1) | |
66 vn = 10; | |
67 z = varargin{1}; | |
68 elseif (nargin == 2) | |
69 vn = varargin{2}; | |
70 z = varargin{1}; | |
7327 | 71 [nr, nc] = size (z); |
72 x = 1:nc; | |
73 y = 1:nr; | |
6257 | 74 elseif (nargin == 3) |
75 vn = 10; | |
76 x = varargin{1}; | |
77 y = varargin{2}; | |
78 z = varargin{3}; | |
79 elseif (nargin == 4) | |
80 vn = varargin{4}; | |
81 x = varargin{1}; | |
82 y = varargin{2}; | |
83 z = varargin{3}; | |
84 else | |
85 print_usage (); | |
86 endif | |
87 | |
10634
60542efcfa2c
Check input arguments for size and type (bug #29861).
Rik <octave@nomad.inbox5.com>
parents:
9758
diff
changeset
|
88 if (!ismatrix (z) || isvector (z) || isscalar (z)) |
60542efcfa2c
Check input arguments for size and type (bug #29861).
Rik <octave@nomad.inbox5.com>
parents:
9758
diff
changeset
|
89 error ("contourc: z argument must be a matrix"); |
60542efcfa2c
Check input arguments for size and type (bug #29861).
Rik <octave@nomad.inbox5.com>
parents:
9758
diff
changeset
|
90 endif |
60542efcfa2c
Check input arguments for size and type (bug #29861).
Rik <octave@nomad.inbox5.com>
parents:
9758
diff
changeset
|
91 |
6257 | 92 if (isscalar (vn)) |
93 vv = linspace (min (z(:)), max (z(:)), vn+2)(2:end-1); | |
94 else | |
95 vv = unique (sort (vn)); | |
96 endif | |
97 | |
7327 | 98 if (isvector (x) && isvector (y)) |
99 c = __contourc__ (x(:)', y(:)', z, vv); | |
100 else | |
101 ## Indexes x,y for the purpose of __contourc__. | |
102 ii = 1:size (z,2); | |
103 jj = 1:size (z,1); | |
104 | |
105 ## Now call __contourc__ for the real work... | |
106 c = __contourc__ (ii, jj, z, vv); | |
107 | |
108 ## Map the contour lines from index space (i,j) back | |
109 ## to the original grid (x,y) | |
110 i = 1; | |
6257 | 111 |
7327 | 112 while (i < size (c,2)) |
113 clen = c(2, i); | |
114 ind = i + [1 : clen]; | |
6257 | 115 |
7327 | 116 ci = c(1, ind); |
117 cj = c(2,ind); | |
118 | |
119 ## due to rounding errors some elements of ci and cj | |
120 ## can fall out of the range of ii and jj and interp2 would | |
121 ## return NA for those values. | |
122 ## The permitted range is enforced here: | |
123 | |
124 ci = max (ci, 1); ci = min (ci, size (z, 2)); | |
125 cj = max (cj, 1); cj = min (cj, size (z, 1)); | |
126 | |
127 c(1, ind) = interp2 (ii, jj, x, ci, cj); | |
128 c(2, ind) = interp2 (ii, jj, y, ci, cj); | |
129 | |
130 i = i + clen + 1; | |
131 endwhile | |
6257 | 132 endif |
7327 | 133 |
8236 | 134 if (nargout > 0) |
135 cout = c; | |
6257 | 136 lev = vv; |
137 endif | |
138 | |
139 endfunction | |
7245 | 140 |
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
|
141 %!test |
7245 | 142 %! x = 0:2; |
143 %! y = x; | |
144 %! 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
|
145 %! [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
|
146 %! 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
|
147 %! lev_expected = [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
|
148 %! assert (c_actual, c_expected, eps) |
a013ff655ca4
Trivial changes to demos to produce a more pleasant output for octave+gnuplot+aquaterm.
Ben Abbott <bpabbott@mac.com>
parents:
8325
diff
changeset
|
149 %! assert (lev_actual, lev_expected, eps) |
a013ff655ca4
Trivial changes to demos to produce a more pleasant output for octave+gnuplot+aquaterm.
Ben Abbott <bpabbott@mac.com>
parents:
8325
diff
changeset
|
150 |
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 |