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 -*- |
6502
|
21 ## @deftypefn {Function File} {[@var{c}, @var{lev}] =} contourc (@var{x}, @var{y}, @var{z}, @var{vv}) |
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 |
|
30 ## @var{c} = [lev1 , x1 , x2 , ... , levn , x1 , x2 , ... |
|
31 ## len1 , y1 , y2 , ... , lenn , y1 , y2 , ... ] |
|
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 ## |
|
44 ## @example |
6502
|
45 ## c = contourc (x, y, z, linspace (0, 2*pi, 10)); |
6257
|
46 ## @end example |
|
47 ## @seealso{contour} |
|
48 ## @end deftypefn |
|
49 |
|
50 ## Author: shaia |
|
51 |
|
52 function [c, lev] = contourc (varargin) |
|
53 |
|
54 if (nargin == 1) |
|
55 vn = 10; |
|
56 z = varargin{1}; |
6269
|
57 x = 1:size(z,2); |
|
58 y = 1:size(z,1); |
6257
|
59 elseif (nargin == 2) |
|
60 vn = varargin{2}; |
|
61 z = varargin{1}; |
6269
|
62 x = 1:size(z,2); |
|
63 y = 1:size(z,1); |
6257
|
64 elseif (nargin == 3) |
|
65 vn = 10; |
|
66 x = varargin{1}; |
|
67 y = varargin{2}; |
|
68 z = varargin{3}; |
|
69 elseif (nargin == 4) |
|
70 vn = varargin{4}; |
|
71 x = varargin{1}; |
|
72 y = varargin{2}; |
|
73 z = varargin{3}; |
|
74 else |
|
75 print_usage (); |
|
76 endif |
|
77 |
|
78 if (isscalar (vn)) |
|
79 vv = linspace (min (z(:)), max (z(:)), vn+2)(2:end-1); |
|
80 else |
|
81 vv = unique (sort (vn)); |
|
82 endif |
|
83 |
|
84 ## Vectorize the x,y vectors, assuming they are output from meshgrid. |
|
85 if (! isvector (x)) |
|
86 x = x(1,:); |
|
87 endif |
|
88 |
|
89 if (! isvector (y)) |
|
90 y = y(:,1); |
|
91 endif |
|
92 |
|
93 ## Make everyone the right dimensions. |
|
94 if (size (x, 2) == 1) |
|
95 x = x'; |
|
96 endif |
|
97 if (size (y, 2) == 1) |
|
98 y = y'; |
|
99 endif |
|
100 |
|
101 ## Now call __contourc__ for the real work... |
|
102 c=__contourc__(x,y,z,vv); |
|
103 if nargout==2, |
|
104 lev = vv; |
|
105 endif |
|
106 |
|
107 endfunction |