Mercurial > hg > octave-nkf
annotate scripts/plot/contourc.m @ 12118:973f585cfdf2 release-3-2-x
include PTHREAD_CFLAGS in LINK_DEPS for liboctave
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 22 Jan 2010 10:21:33 +0100 |
parents | 1bf0ce0930be |
children | 09da0bd91412 |
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 -*- | |
6590 | 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 |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
30 ## @var{c} = [lev1, x1, x2, @dots{}, levn, x1, x2, @dots{} |
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 ## | |
6592 | 45 ## For example, |
6257 | 46 ## @example |
6592 | 47 ## @group |
48 ## x = 0:2; | |
49 ## y = x; | |
50 ## z = x' * y; | |
51 ## contourc (x, y, z, 2:3) | |
52 ## @result{} 2.0000 2.0000 1.0000 3.0000 1.5000 2.0000 | |
53 ## 2.0000 1.0000 2.0000 2.0000 2.0000 1.5000 | |
54 ## | |
55 ## @end group | |
6257 | 56 ## @end example |
57 ## @seealso{contour} | |
58 ## @end deftypefn | |
59 | |
7327 | 60 ## Author: Shai Ayal <shaiay@users.sourceforge.net> |
6257 | 61 |
8236 | 62 function [cout, lev] = contourc (varargin) |
6257 | 63 |
64 if (nargin == 1) | |
65 vn = 10; | |
66 z = varargin{1}; | |
7327 | 67 [nr, nc] = size (z); |
68 x = 1:nc; | |
69 y = 1:nr; | |
6257 | 70 elseif (nargin == 2) |
71 vn = varargin{2}; | |
72 z = varargin{1}; | |
7327 | 73 [nr, nc] = size (z); |
74 x = 1:nc; | |
75 y = 1:nr; | |
6257 | 76 elseif (nargin == 3) |
77 vn = 10; | |
78 x = varargin{1}; | |
79 y = varargin{2}; | |
80 z = varargin{3}; | |
81 elseif (nargin == 4) | |
82 vn = varargin{4}; | |
83 x = varargin{1}; | |
84 y = varargin{2}; | |
85 z = varargin{3}; | |
86 else | |
87 print_usage (); | |
88 endif | |
89 | |
90 if (isscalar (vn)) | |
91 vv = linspace (min (z(:)), max (z(:)), vn+2)(2:end-1); | |
92 else | |
93 vv = unique (sort (vn)); | |
94 endif | |
95 | |
7327 | 96 if (isvector (x) && isvector (y)) |
97 c = __contourc__ (x(:)', y(:)', z, vv); | |
98 else | |
99 ## Indexes x,y for the purpose of __contourc__. | |
100 ii = 1:size (z,2); | |
101 jj = 1:size (z,1); | |
102 | |
103 ## Now call __contourc__ for the real work... | |
104 c = __contourc__ (ii, jj, z, vv); | |
105 | |
106 ## Map the contour lines from index space (i,j) back | |
107 ## to the original grid (x,y) | |
108 i = 1; | |
6257 | 109 |
7327 | 110 while (i < size (c,2)) |
111 clen = c(2, i); | |
112 ind = i + [1 : clen]; | |
6257 | 113 |
7327 | 114 ci = c(1, ind); |
115 cj = c(2,ind); | |
116 | |
117 ## due to rounding errors some elements of ci and cj | |
118 ## can fall out of the range of ii and jj and interp2 would | |
119 ## return NA for those values. | |
120 ## The permitted range is enforced here: | |
121 | |
122 ci = max (ci, 1); ci = min (ci, size (z, 2)); | |
123 cj = max (cj, 1); cj = min (cj, size (z, 1)); | |
124 | |
125 c(1, ind) = interp2 (ii, jj, x, ci, cj); | |
126 c(2, ind) = interp2 (ii, jj, y, ci, cj); | |
127 | |
128 i = i + clen + 1; | |
129 endwhile | |
6257 | 130 endif |
7327 | 131 |
8236 | 132 if (nargout > 0) |
133 cout = c; | |
6257 | 134 lev = vv; |
135 endif | |
136 | |
137 endfunction | |
7245 | 138 |
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
|
139 %!test |
7245 | 140 %! x = 0:2; |
141 %! y = x; | |
142 %! 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
|
143 %! [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
|
144 %! 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
|
145 %! 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
|
146 %! 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
|
147 %! 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
|
148 |
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 |