6257
|
1 ## Copyright (C) 2003 Shai Ayal |
2313
|
2 ## |
6257
|
3 ## This program is free software; you can redistribute it and/or modify it |
2313
|
4 ## under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2, or (at your option) |
|
6 ## any later version. |
|
7 ## |
6257
|
8 ## OctPlot is distributed in the hope that it will be useful, but |
2313
|
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
11 ## General Public License for more details. |
|
12 ## |
|
13 ## You should have received a copy of the GNU General Public License |
6257
|
14 ## along with OctPlot; see the file COPYING. If not, write to the Free |
|
15 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
16 ## 02111-1307, USA. |
245
|
17 |
3368
|
18 ## -*- texinfo -*- |
6257
|
19 ## @deftypefn {Function File} {} {@var{c}} = contour (@var{x},@var{y},@var{z},@var{vv}) |
|
20 ## Compute isolines (countour lines) of the matrix @var{z}. |
|
21 ## parameters @var{x}, @var{y} and @var{vn} are optional. |
|
22 ## |
|
23 ## The return value @var{c} is a 2 by @var{n} matrix containing the |
|
24 ## contour lines in the following format |
|
25 ## |
|
26 ## @example |
|
27 ## @var{c} = [lev1 , x1 , x2 , ... , levn , x1 , x2 , ... |
|
28 ## len1 , y1 , y2 , ... , lenn , y1 , y2 , ... ] |
|
29 ## @end example |
|
30 ## |
|
31 ## @noindent |
|
32 ## in which contour line @var{n} has a level (height) of @var{levn} and |
|
33 ## length of @var{lenn}. |
|
34 ## |
|
35 ## If @var{x} and @var{y} are omitted they are taken as the row/column |
|
36 ## index of @var{z}. @var{vn} is either a scalar denoting the number of |
|
37 ## lines to compute or a vector containing the values of the lines. If |
|
38 ## only one value is wanted, set @code{@var{vn} = [val, val]}. If |
|
39 ## @var{vn} is omitted it defaults to 10. |
|
40 ## |
|
41 ## @example |
|
42 ## @var{c}=contourc (@var{x}, @var{y}, @var{z}, linspace(0,2*pi,10)) |
|
43 ## @end example |
|
44 ## @seealso{contourc,line,plot} |
3368
|
45 ## @end deftypefn |
4
|
46 |
2314
|
47 |
6257
|
48 ## Author: shaia |
|
49 |
|
50 function retval = contour (varargin) |
4
|
51 |
6257
|
52 [c, lev] = contourc (varargin{:}); |
6172
|
53 |
6257
|
54 cmap = get (gcf(), "colormap"); |
|
55 |
|
56 levx = linspace (min (lev), max (lev), size (cmap, 1)); |
|
57 |
|
58 newplot (); |
3063
|
59 |
6257
|
60 ## decode contourc output format |
|
61 i1 = 1; |
|
62 while (i1 < length (c)) |
|
63 clev = c(1,i1); |
|
64 clen = c(2,i1); |
|
65 |
|
66 ccr = interp1 (levx, cmap(:,1), clev); |
|
67 ccg = interp1 (levx, cmap(:,2), clev); |
|
68 ccb = interp1 (levx, cmap(:,3), clev); |
|
69 |
|
70 ii = i1+1:i1+clen; |
6279
|
71 line (c(1,ii), c(2,ii), "color", [ccr, ccg, ccb]); |
6257
|
72 |
|
73 i1 += c(2,i1)+1; |
|
74 endwhile |
|
75 |
|
76 drawnow (); |
|
77 |
|
78 ## folowing DM's suggestion to surpress output if none asked for |
|
79 if (nargout > 0) |
|
80 retval = c; |
4
|
81 endif |
|
82 |
|
83 endfunction |
6257
|
84 |
|
85 |