7109
|
1 ## Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2002, 2004, |
|
2 ## 2005, 2006, 2007 John W. Eaton |
|
3 ## |
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
|
7 ## under the terms of the GNU General Public License as published by |
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
|
10 ## |
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
|
19 |
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} @var{h} = {} surface (@var{x}, @var{y}, @var{z}, @var{c}) |
|
22 ## @deftypefnx {Function File} @var{h} = {} surface (@var{x}, @var{y}, @var{z}) |
|
23 ## Plot a surface graphic object given matrices @var{x}, and @var{y} from @code{meshgrid} and |
|
24 ## a matrix @var{z} corresponding to the @var{x} and @var{y} coordinates of |
|
25 ## the surface. If @var{x} and @var{y} are vectors, then a typical vertex |
|
26 ## is (@var{x}(j), @var{y}(i), @var{z}(i,j)). Thus, columns of @var{z} |
|
27 ## correspond to different @var{x} values and rows of @var{z} correspond |
|
28 ## to different @var{y} values. |
|
29 ## @seealso{surf, mesh, patch, line} |
|
30 ## @end deftypefn |
|
31 |
|
32 ## Author: jwe |
|
33 |
|
34 function h = surface (x, y, z, c) |
|
35 |
7110
|
36 ax = gca (); |
7109
|
37 |
|
38 if (nargin == 1) |
|
39 c = z = x; |
|
40 if (ismatrix (z)) |
|
41 [nr, nc] = size (z); |
|
42 x = 1:nc; |
|
43 y = (1:nr)'; |
|
44 else |
|
45 error ("surface: argument must be a matrix"); |
|
46 endif |
|
47 elseif (nargin == 3) |
7110
|
48 c = z; |
7109
|
49 if (isvector (x) && isvector (y) && ismatrix (z)) |
|
50 if (rows (z) == length (y) && columns (z) == length (x)) |
|
51 x = x(:)'; |
|
52 y = y(:); |
|
53 else |
7110
|
54 error ("surface: rows (z) must be the same as length (y) and columns (z) must be the same as length (x)"); |
7109
|
55 endif |
|
56 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) |
|
57 if (! (size_equal (x, y) && size_equal (x, z))) |
|
58 error ("surface: x, y, and z must have same dimensions"); |
|
59 endif |
|
60 else |
|
61 error ("surface: x and y must be vectors and z must be a matrix"); |
|
62 endif |
|
63 elseif (nargin == 4) |
7110
|
64 if (! size_equal (z, c)) |
7109
|
65 error ("surface: z and c must have same size"); |
|
66 endif |
|
67 if (isvector (x) && isvector (y) && ismatrix (z)) |
|
68 if (rows (z) == length (y) && columns (z) == length (x)) |
|
69 x = x(:)'; |
|
70 y = y(:); |
|
71 else |
7114
|
72 error ("surface: rows (z) must be the same as length (y) and columns (z) must be the same as length (x)"); |
7109
|
73 endif |
|
74 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) |
|
75 if (! (size_equal (x, y) && size_equal (x, z))) |
|
76 error ("surface: x, y, and z must have same dimensions"); |
|
77 endif |
|
78 else |
|
79 error ("surface: x and y must be vectors and z must be a matrix"); |
|
80 endif |
|
81 else |
|
82 print_usage (); |
|
83 endif |
|
84 |
7110
|
85 ## Make a default surface object. |
7109
|
86 tmp = __go_surface__ (ax, "xdata", x, "ydata", y, "zdata", z, "cdata", c); |
7146
|
87 set (tmp, "facecolor","flat"); |
7109
|
88 |
7146
|
89 if (! ishold ()) |
|
90 set (ax, "view", [0, 90], "box", "off", "xgrid", "on", "ygrid", "on", "zgrid", "on"); |
|
91 endif |
7109
|
92 |
|
93 if (nargout > 0) |
|
94 h = tmp; |
|
95 endif |
|
96 |
|
97 endfunction |