6257
|
1 ## Copyright (C) 2003 Shai Ayal |
|
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}) |
6257
|
21 ## Compute isolines (countour lines) of the matrix @var{z}. |
|
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 |
6547
|
29 ## @var{c} = [lev1, x1, x2, ..., levn, x1, x2, ... |
|
30 ## len1, y1, y2, ..., lenn, y1, y2, ...] |
6257
|
31 ## @end example |
|
32 ## |
|
33 ## @noindent |
|
34 ## in which contour line @var{n} has a level (height) of @var{levn} and |
|
35 ## length of @var{lenn}. |
|
36 ## |
|
37 ## If @var{x} and @var{y} are omitted they are taken as the row/column |
|
38 ## index of @var{z}. @var{vn} is either a scalar denoting the number of lines |
|
39 ## to compute or a vector containing the values of the lines. If only one |
|
40 ## value is wanted, set @code{@var{vn} = [val, val]}; |
|
41 ## If @var{vn} is omitted it defaults to 10. |
|
42 ## |
6592
|
43 ## For example, |
6257
|
44 ## @example |
6592
|
45 ## @group |
|
46 ## x = 0:2; |
|
47 ## y = x; |
|
48 ## z = x' * y; |
|
49 ## contourc (x, y, z, 2:3) |
|
50 ## @result{} 2.0000 2.0000 1.0000 3.0000 1.5000 2.0000 |
|
51 ## 2.0000 1.0000 2.0000 2.0000 2.0000 1.5000 |
|
52 ## |
|
53 ## @end group |
6257
|
54 ## @end example |
|
55 ## @seealso{contour} |
|
56 ## @end deftypefn |
|
57 |
|
58 ## Author: shaia |
|
59 |
|
60 function [c, lev] = contourc (varargin) |
|
61 |
|
62 if (nargin == 1) |
|
63 vn = 10; |
|
64 z = varargin{1}; |
6269
|
65 x = 1:size(z,2); |
|
66 y = 1:size(z,1); |
6257
|
67 elseif (nargin == 2) |
|
68 vn = varargin{2}; |
|
69 z = varargin{1}; |
6269
|
70 x = 1:size(z,2); |
|
71 y = 1:size(z,1); |
6257
|
72 elseif (nargin == 3) |
|
73 vn = 10; |
|
74 x = varargin{1}; |
|
75 y = varargin{2}; |
|
76 z = varargin{3}; |
|
77 elseif (nargin == 4) |
|
78 vn = varargin{4}; |
|
79 x = varargin{1}; |
|
80 y = varargin{2}; |
|
81 z = varargin{3}; |
|
82 else |
|
83 print_usage (); |
|
84 endif |
|
85 |
|
86 if (isscalar (vn)) |
|
87 vv = linspace (min (z(:)), max (z(:)), vn+2)(2:end-1); |
|
88 else |
|
89 vv = unique (sort (vn)); |
|
90 endif |
|
91 |
|
92 ## Vectorize the x,y vectors, assuming they are output from meshgrid. |
|
93 if (! isvector (x)) |
|
94 x = x(1,:); |
|
95 endif |
|
96 |
|
97 if (! isvector (y)) |
|
98 y = y(:,1); |
|
99 endif |
|
100 |
|
101 ## Make everyone the right dimensions. |
|
102 if (size (x, 2) == 1) |
|
103 x = x'; |
|
104 endif |
|
105 if (size (y, 2) == 1) |
|
106 y = y'; |
|
107 endif |
|
108 |
|
109 ## Now call __contourc__ for the real work... |
6895
|
110 c = __contourc__ (x, y, z, vv); |
|
111 if (nargout == 2) |
6257
|
112 lev = vv; |
|
113 endif |
|
114 |
|
115 endfunction |