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 -*- |
6547
|
21 ## @deftypefn {Function File} {} {@var{c} =} contour (@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{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 |
|
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 |
6547
|
44 ## levels = linspace (0, 2*pi, 10); |
|
45 ## @var{c} = contourc (@var{x}, @var{y}, @var{z}, levels); |
6257
|
46 ## @end example |
6547
|
47 ## @seealso{contourc, line, plot} |
3368
|
48 ## @end deftypefn |
4
|
49 |
6257
|
50 ## Author: shaia |
|
51 |
|
52 function retval = contour (varargin) |
4
|
53 |
6257
|
54 [c, lev] = contourc (varargin{:}); |
6172
|
55 |
6257
|
56 cmap = get (gcf(), "colormap"); |
|
57 |
|
58 levx = linspace (min (lev), max (lev), size (cmap, 1)); |
|
59 |
|
60 newplot (); |
3063
|
61 |
6434
|
62 ## Decode contourc output format. |
6257
|
63 i1 = 1; |
|
64 while (i1 < length (c)) |
6434
|
65 |
6257
|
66 clev = c(1,i1); |
|
67 clen = c(2,i1); |
|
68 |
|
69 ccr = interp1 (levx, cmap(:,1), clev); |
|
70 ccg = interp1 (levx, cmap(:,2), clev); |
|
71 ccb = interp1 (levx, cmap(:,3), clev); |
|
72 |
|
73 ii = i1+1:i1+clen; |
6279
|
74 line (c(1,ii), c(2,ii), "color", [ccr, ccg, ccb]); |
6257
|
75 |
|
76 i1 += c(2,i1)+1; |
|
77 endwhile |
|
78 |
|
79 if (nargout > 0) |
|
80 retval = c; |
4
|
81 endif |
|
82 |
|
83 endfunction |
6257
|
84 |
|
85 |