6257
|
1 ## Copyright (C) 2003 Shai Ayal |
2313
|
2 ## |
6440
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
2313
|
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 |
2313
|
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. |
245
|
19 |
3368
|
20 ## -*- texinfo -*- |
6257
|
21 ## @deftypefn {Function File} {} {@var{c}} = contour (@var{x},@var{y},@var{z},@var{vv}) |
|
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{c} is a 2 by @var{n} matrix containing the |
|
26 ## contour lines in the following format |
|
27 ## |
|
28 ## @example |
|
29 ## @var{c} = [lev1 , x1 , x2 , ... , levn , x1 , x2 , ... |
|
30 ## len1 , y1 , y2 , ... , lenn , y1 , y2 , ... ] |
|
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 |
|
39 ## lines to compute or a vector containing the values of the lines. If |
|
40 ## only one value is wanted, set @code{@var{vn} = [val, val]}. If |
|
41 ## @var{vn} is omitted it defaults to 10. |
|
42 ## |
|
43 ## @example |
|
44 ## @var{c}=contourc (@var{x}, @var{y}, @var{z}, linspace(0,2*pi,10)) |
|
45 ## @end example |
|
46 ## @seealso{contourc,line,plot} |
3368
|
47 ## @end deftypefn |
4
|
48 |
6257
|
49 ## Author: shaia |
|
50 |
|
51 function retval = contour (varargin) |
4
|
52 |
6257
|
53 [c, lev] = contourc (varargin{:}); |
6172
|
54 |
6257
|
55 cmap = get (gcf(), "colormap"); |
|
56 |
|
57 levx = linspace (min (lev), max (lev), size (cmap, 1)); |
|
58 |
|
59 newplot (); |
3063
|
60 |
6434
|
61 ## Decode contourc output format. |
6257
|
62 i1 = 1; |
|
63 while (i1 < length (c)) |
6434
|
64 |
6257
|
65 clev = c(1,i1); |
|
66 clen = c(2,i1); |
|
67 |
|
68 ccr = interp1 (levx, cmap(:,1), clev); |
|
69 ccg = interp1 (levx, cmap(:,2), clev); |
|
70 ccb = interp1 (levx, cmap(:,3), clev); |
|
71 |
|
72 ii = i1+1:i1+clen; |
6279
|
73 line (c(1,ii), c(2,ii), "color", [ccr, ccg, ccb]); |
6257
|
74 |
|
75 i1 += c(2,i1)+1; |
|
76 endwhile |
|
77 |
|
78 if (nargout > 0) |
|
79 retval = c; |
4
|
80 endif |
|
81 |
|
82 endfunction |
6257
|
83 |
|
84 |