6788
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
6788
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
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 |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
6788
|
18 |
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {} meshc (@var{x}, @var{y}, @var{z}) |
|
21 ## Plot a mesh and contour given matrices @var{x}, and @var{y} from |
|
22 ## @code{meshgrid} and a matrix @var{z} corresponding to the @var{x} and |
|
23 ## @var{y} coordinates of the mesh. If @var{x} and @var{y} are vectors, |
|
24 ## then a typical vertex is (@var{x}(j), @var{y}(i), @var{z}(i,j)). Thus, |
|
25 ## columns of @var{z} correspond to different @var{x} values and rows of |
|
26 ## @var{z} correspond to different @var{y} values. |
|
27 ## @seealso{meshgrid, mesh, contour} |
|
28 ## @end deftypefn |
|
29 |
|
30 function h = meshc (varargin) |
|
31 |
|
32 newplot (); |
|
33 |
|
34 if (nargin == 1) |
|
35 z = varargin{1}; |
|
36 if (ismatrix (z)) |
|
37 [nr, nc] = size (z); |
|
38 x = 1:nc; |
|
39 y = (1:nr)'; |
|
40 else |
|
41 error ("meshc: argument must be a matrix"); |
|
42 endif |
|
43 elseif (nargin == 3) |
|
44 x = varargin{1}; |
|
45 y = varargin{2}; |
|
46 z = varargin{3}; |
|
47 |
|
48 if (isvector (x) && isvector (y) && ismatrix (z)) |
|
49 if (rows (z) == length (y) && columns (z) == length (x)) |
|
50 x = x(:)'; |
|
51 y = y(:); |
|
52 else |
|
53 msg = "meshc: rows (z) must be the same as length (y) and"; |
|
54 msg = sprintf ("%s\ncolumns (z) must be the same as length (x)", msg); |
|
55 error (msg); |
|
56 endif |
|
57 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) |
|
58 if (! (size_equal (x, y) && size_equal (x, z))) |
|
59 error ("meshc: x, y, and z must have same dimensions"); |
|
60 endif |
|
61 else |
|
62 error ("meshc: x and y must be vectors and z must be a matrix"); |
|
63 endif |
|
64 else |
|
65 print_usage (); |
|
66 endif |
|
67 |
|
68 ## make a default line object, and make it the current axes for the |
|
69 ## current figure. |
|
70 ca = gca (); |
|
71 |
|
72 tmp = __go_surface__ (ca, "xdata", x, "ydata", y, "zdata", z); |
|
73 |
|
74 set (ca, "view", [-37.5, 30]); |
|
75 |
|
76 hold on; |
|
77 |
|
78 [c, lev] = contourc (varargin{:}); |
|
79 |
|
80 cmap = get (gcf(), "colormap"); |
|
81 |
|
82 levx = linspace (min (lev), max (lev), size (cmap, 1)); |
|
83 |
|
84 drawnow(); |
|
85 ax = axis(); |
|
86 zmin = 2 * ax(5) - ax(6); |
|
87 |
|
88 ## decode contourc output format |
|
89 i1 = 1; |
|
90 while (i1 < length (c)) |
|
91 |
|
92 clev = c(1,i1); |
|
93 clen = c(2,i1); |
|
94 |
|
95 ccr = interp1 (levx, cmap(:,1), clev); |
|
96 ccg = interp1 (levx, cmap(:,2), clev); |
|
97 ccb = interp1 (levx, cmap(:,3), clev); |
|
98 |
|
99 ii = i1+1:i1+clen; |
|
100 line (c(1,ii), c(2,ii), zmin*ones(size(ii)), "color", [ccr, ccg, ccb]); |
|
101 |
|
102 i1 += c(2,i1)+1; |
|
103 endwhile |
|
104 |
|
105 if (nargout > 0) |
|
106 h = tmp; |
|
107 endif |
|
108 endfunction |