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 |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
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 |
6440
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
6257
|
19 |
|
20 ## -*- texinfo -*- |
6590
|
21 ## @deftypefn {Function File} {[@var{c}, @var{lev}] =} contourc (@var{x}, @var{y}, @var{z}, @var{vn}) |
6257
|
22 ## Compute isolines (countour lines) of the matrix @var{z}. |
|
23 ## Parameters @var{x}, @var{y} and @var{vn} are optional. |
|
24 ## |
|
25 ## The return value @var{lev} is a vector of the contour levels. |
|
26 ## The return value @var{c} is a 2 by @var{n} matrix containing the |
|
27 ## contour lines in the following format |
|
28 ## |
|
29 ## @example |
6547
|
30 ## @var{c} = [lev1, x1, x2, ..., levn, x1, x2, ... |
|
31 ## len1, y1, y2, ..., lenn, y1, y2, ...] |
6257
|
32 ## @end example |
|
33 ## |
|
34 ## @noindent |
|
35 ## in which contour line @var{n} has a level (height) of @var{levn} and |
|
36 ## length of @var{lenn}. |
|
37 ## |
|
38 ## If @var{x} and @var{y} are omitted they are taken as the row/column |
|
39 ## index of @var{z}. @var{vn} is either a scalar denoting the number of lines |
|
40 ## to compute or a vector containing the values of the lines. If only one |
|
41 ## value is wanted, set @code{@var{vn} = [val, val]}; |
|
42 ## If @var{vn} is omitted it defaults to 10. |
|
43 ## |
6592
|
44 ## For example, |
6257
|
45 ## @example |
6592
|
46 ## @group |
|
47 ## x = 0:2; |
|
48 ## y = x; |
|
49 ## z = x' * y; |
|
50 ## contourc (x, y, z, 2:3) |
|
51 ## @result{} 2.0000 2.0000 1.0000 3.0000 1.5000 2.0000 |
|
52 ## 2.0000 1.0000 2.0000 2.0000 2.0000 1.5000 |
|
53 ## |
|
54 ## @end group |
6257
|
55 ## @end example |
|
56 ## @seealso{contour} |
|
57 ## @end deftypefn |
|
58 |
|
59 ## Author: shaia |
|
60 |
|
61 function [c, lev] = contourc (varargin) |
|
62 |
|
63 if (nargin == 1) |
|
64 vn = 10; |
|
65 z = varargin{1}; |
6269
|
66 x = 1:size(z,2); |
|
67 y = 1:size(z,1); |
6257
|
68 elseif (nargin == 2) |
|
69 vn = varargin{2}; |
|
70 z = varargin{1}; |
6269
|
71 x = 1:size(z,2); |
|
72 y = 1:size(z,1); |
6257
|
73 elseif (nargin == 3) |
|
74 vn = 10; |
|
75 x = varargin{1}; |
|
76 y = varargin{2}; |
|
77 z = varargin{3}; |
|
78 elseif (nargin == 4) |
|
79 vn = varargin{4}; |
|
80 x = varargin{1}; |
|
81 y = varargin{2}; |
|
82 z = varargin{3}; |
|
83 else |
|
84 print_usage (); |
|
85 endif |
|
86 |
|
87 if (isscalar (vn)) |
|
88 vv = linspace (min (z(:)), max (z(:)), vn+2)(2:end-1); |
|
89 else |
|
90 vv = unique (sort (vn)); |
|
91 endif |
|
92 |
|
93 ## Vectorize the x,y vectors, assuming they are output from meshgrid. |
|
94 if (! isvector (x)) |
|
95 x = x(1,:); |
|
96 endif |
|
97 |
|
98 if (! isvector (y)) |
|
99 y = y(:,1); |
|
100 endif |
|
101 |
|
102 ## Make everyone the right dimensions. |
|
103 if (size (x, 2) == 1) |
|
104 x = x'; |
|
105 endif |
|
106 if (size (y, 2) == 1) |
|
107 y = y'; |
|
108 endif |
|
109 |
|
110 ## Now call __contourc__ for the real work... |
|
111 c=__contourc__(x,y,z,vv); |
|
112 if nargout==2, |
|
113 lev = vv; |
|
114 endif |
|
115 |
|
116 endfunction |