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 |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
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 |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
245
|
19 |
3368
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} mesh (@var{x}, @var{y}, @var{z}) |
6154
|
22 ## Plot a mesh given matrices @var{x}, and @var{y} from @code{meshgrid} and |
3368
|
23 ## a matrix @var{z} corresponding to the @var{x} and @var{y} coordinates of |
|
24 ## the mesh. If @var{x} and @var{y} are vectors, then a typical vertex |
|
25 ## is (@var{x}(j), @var{y}(i), @var{z}(i,j)). Thus, columns of @var{z} |
|
26 ## correspond to different @var{x} values and rows of @var{z} correspond |
|
27 ## to different @var{y} values. |
5642
|
28 ## @seealso{meshgrid, contour} |
3368
|
29 ## @end deftypefn |
4
|
30 |
2314
|
31 ## Author: jwe |
|
32 |
6257
|
33 function h = mesh (x, y, z) |
6172
|
34 |
6390
|
35 newplot (); |
|
36 |
4
|
37 if (nargin == 1) |
|
38 z = x; |
4030
|
39 if (ismatrix (z)) |
6257
|
40 [nr, nc] = size (z); |
|
41 x = 1:nc; |
|
42 y = (1:nr)'; |
4
|
43 else |
|
44 error ("mesh: argument must be a matrix"); |
|
45 endif |
|
46 elseif (nargin == 3) |
4030
|
47 if (isvector (x) && isvector (y) && ismatrix (z)) |
6154
|
48 if (rows (z) == length (y) && columns (z) == length (x)) |
6257
|
49 x = x(:)'; |
|
50 y = y(:); |
4
|
51 else |
3474
|
52 msg = "mesh: rows (z) must be the same as length (y) and"; |
|
53 msg = sprintf ("%s\ncolumns (z) must be the same as length (x)", msg); |
904
|
54 error (msg); |
4
|
55 endif |
4030
|
56 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) |
6156
|
57 if (! (size_equal (x, y) && size_equal (x, z))) |
1712
|
58 error ("mesh: x, y, and z must have same dimensions"); |
|
59 endif |
4
|
60 else |
|
61 error ("mesh: x and y must be vectors and z must be a matrix"); |
2325
|
62 endif |
4
|
63 else |
6046
|
64 print_usage (); |
4
|
65 endif |
|
66 |
6257
|
67 ## make a default line object, and make it the current axes for the |
|
68 ## current figure. |
|
69 ca = gca (); |
|
70 |
|
71 s = __uiobject_surface_ctor__ (ca); |
|
72 |
|
73 s.xdata = x; |
|
74 s.ydata = y; |
|
75 s.zdata = z; |
|
76 |
|
77 set (ca, "view", [-37.5, 30]); |
|
78 |
|
79 tmp = __uiobject_make_handle__ (s); |
|
80 |
|
81 __uiobject_adopt__ (ca, tmp); |
|
82 |
|
83 if (nargout > 0) |
|
84 h = tmp; |
6154
|
85 endif |
|
86 |
4
|
87 endfunction |