2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
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. |
2313
|
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/>. |
245
|
18 |
3368
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {} mesh (@var{x}, @var{y}, @var{z}) |
6154
|
21 ## Plot a mesh given matrices @var{x}, and @var{y} from @code{meshgrid} and |
3368
|
22 ## a matrix @var{z} corresponding to the @var{x} and @var{y} coordinates of |
|
23 ## the mesh. If @var{x} and @var{y} are vectors, then a typical vertex |
|
24 ## is (@var{x}(j), @var{y}(i), @var{z}(i,j)). Thus, columns of @var{z} |
|
25 ## correspond to different @var{x} values and rows of @var{z} correspond |
|
26 ## to different @var{y} values. |
5642
|
27 ## @seealso{meshgrid, contour} |
3368
|
28 ## @end deftypefn |
4
|
29 |
2314
|
30 ## Author: jwe |
|
31 |
6257
|
32 function h = mesh (x, y, z) |
6172
|
33 |
6390
|
34 newplot (); |
|
35 |
4
|
36 if (nargin == 1) |
|
37 z = x; |
4030
|
38 if (ismatrix (z)) |
6257
|
39 [nr, nc] = size (z); |
|
40 x = 1:nc; |
|
41 y = (1:nr)'; |
4
|
42 else |
|
43 error ("mesh: argument must be a matrix"); |
|
44 endif |
|
45 elseif (nargin == 3) |
4030
|
46 if (isvector (x) && isvector (y) && ismatrix (z)) |
6154
|
47 if (rows (z) == length (y) && columns (z) == length (x)) |
6257
|
48 x = x(:)'; |
|
49 y = y(:); |
4
|
50 else |
3474
|
51 msg = "mesh: rows (z) must be the same as length (y) and"; |
|
52 msg = sprintf ("%s\ncolumns (z) must be the same as length (x)", msg); |
904
|
53 error (msg); |
4
|
54 endif |
4030
|
55 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) |
6156
|
56 if (! (size_equal (x, y) && size_equal (x, z))) |
1712
|
57 error ("mesh: x, y, and z must have same dimensions"); |
|
58 endif |
4
|
59 else |
|
60 error ("mesh: x and y must be vectors and z must be a matrix"); |
2325
|
61 endif |
4
|
62 else |
6046
|
63 print_usage (); |
4
|
64 endif |
|
65 |
6257
|
66 ## make a default line object, and make it the current axes for the |
|
67 ## current figure. |
|
68 ca = gca (); |
|
69 |
6405
|
70 tmp = __go_surface__ (ca, "xdata", x, "ydata", y, "zdata", z); |
6257
|
71 |
|
72 set (ca, "view", [-37.5, 30]); |
|
73 |
|
74 if (nargout > 0) |
|
75 h = tmp; |
6154
|
76 endif |
|
77 |
4
|
78 endfunction |