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 -*- |
7175
|
21 ## @deftypefn {Function File} {} surface (@var{x}, @var{y}, @var{z}, @var{c}) |
|
22 ## @deftypefnx {Function File} {} surface (@var{x}, @var{y}, @var{z}) |
|
23 ## @deftypefnx {Function File} {} surface (@var{z}, @var{c}) |
|
24 ## @deftypefnx {Function File} {} surface (@var{z}) |
|
25 ## @deftypefnx {Function File} {} surface (@dots{}, @var{prop}, @var{val}) |
|
26 ## @deftypefnx {Function File} {} surface (@var{h}, @dots{}) |
|
27 ## @deftypefnx {Function File} {@var{h} = } surface (@dots{}) |
|
28 ## Plot a surface graphic object given matrices @var{x}, and @var{y} from |
|
29 ## @code{meshgrid} and a matrix @var{z} corresponding to the @var{x} and |
|
30 ## @var{y} coordinates of the surface. If @var{x} and @var{y} are vectors, |
|
31 ## then a typical vertex is (@var{x}(j), @var{y}(i), @var{z}(i,j)). Thus, |
|
32 ## columns of @var{z} correspond to different @var{x} values and rows of |
|
33 ## @var{z} correspond to different @var{y} values. If @var{x} and @var{y} |
|
34 ## are missing, they are constructed from size of the matrix @var{z}. |
|
35 ## |
|
36 ## Any additional properties passed are assigned the the surface.. |
7109
|
37 ## @seealso{surf, mesh, patch, line} |
|
38 ## @end deftypefn |
|
39 |
|
40 ## Author: jwe |
|
41 |
7175
|
42 function h = surface (varargin) |
7109
|
43 |
7110
|
44 ax = gca (); |
7109
|
45 |
7175
|
46 firststring = nargin + 1; |
|
47 for i = 1 : nargin |
|
48 if (ischar (varargin {i})) |
|
49 firststring = i; |
|
50 break; |
7109
|
51 endif |
7175
|
52 endfor |
|
53 |
|
54 |
|
55 if (firststring > 5) |
|
56 print_usage (); |
|
57 elseif (firststring == 5) |
|
58 x = varargin{1}; |
|
59 y = varargin{2}; |
|
60 z = varargin{3}; |
|
61 c = varargin{4}; |
|
62 |
7110
|
63 if (! size_equal (z, c)) |
7109
|
64 error ("surface: z and c must have same size"); |
|
65 endif |
|
66 if (isvector (x) && isvector (y) && ismatrix (z)) |
|
67 if (rows (z) == length (y) && columns (z) == length (x)) |
|
68 x = x(:)'; |
|
69 y = y(:); |
|
70 else |
7114
|
71 error ("surface: rows (z) must be the same as length (y) and columns (z) must be the same as length (x)"); |
7109
|
72 endif |
|
73 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) |
|
74 if (! (size_equal (x, y) && size_equal (x, z))) |
|
75 error ("surface: x, y, and z must have same dimensions"); |
|
76 endif |
|
77 else |
|
78 error ("surface: x and y must be vectors and z must be a matrix"); |
|
79 endif |
7175
|
80 elseif (firststring == 4) |
|
81 x = varargin{1}; |
|
82 y = varargin{2}; |
|
83 z = varargin{3}; |
|
84 c = z; |
|
85 if (isvector (x) && isvector (y) && ismatrix (z)) |
|
86 if (rows (z) == length (y) && columns (z) == length (x)) |
|
87 x = x(:)'; |
|
88 y = y(:); |
|
89 else |
|
90 error ("surface: rows (z) must be the same as length (y) and columns (z) must be the same as length (x)"); |
|
91 endif |
|
92 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) |
|
93 if (! (size_equal (x, y) && size_equal (x, z))) |
|
94 error ("surface: x, y, and z must have same dimensions"); |
|
95 endif |
|
96 else |
|
97 error ("surface: x and y must be vectors and z must be a matrix"); |
|
98 endif |
|
99 elseif (firststring == 3) |
|
100 z = varargin {1}; |
|
101 c = varargin {2}; |
|
102 if (ismatrix (z)) |
|
103 [nr, nc] = size (z); |
|
104 x = 1:nc; |
|
105 y = (1:nr)'; |
|
106 else |
|
107 error ("surface: argument must be a matrix"); |
|
108 endif |
|
109 elseif (firststring == 2) |
|
110 z = varargin {1}; |
|
111 c = z; |
|
112 if (ismatrix (z)) |
|
113 [nr, nc] = size (z); |
|
114 x = 1:nc; |
|
115 y = (1:nr)'; |
|
116 else |
|
117 error ("surface: argument must be a matrix"); |
|
118 endif |
7109
|
119 else |
|
120 print_usage (); |
|
121 endif |
|
122 |
7110
|
123 ## Make a default surface object. |
7109
|
124 tmp = __go_surface__ (ax, "xdata", x, "ydata", y, "zdata", z, "cdata", c); |
7146
|
125 set (tmp, "facecolor","flat"); |
7189
|
126 if (firststring <= nargin) |
|
127 set (tmp, varargin {firststring:end}); |
|
128 endif |
7109
|
129 |
7146
|
130 if (! ishold ()) |
|
131 set (ax, "view", [0, 90], "box", "off", "xgrid", "on", "ygrid", "on", "zgrid", "on"); |
|
132 endif |
7109
|
133 |
|
134 if (nargout > 0) |
|
135 h = tmp; |
|
136 endif |
|
137 |
|
138 endfunction |