1 ## Copyright (C) 1993-2012 John W. Eaton
3 ## This file is part of Octave.
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 3 of the License, or (at
8 ## your option) any later version.
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.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} surface (@var{x}, @var{y}, @var{z}, @var{c})
21 ## @deftypefnx {Function File} {} surface (@var{x}, @var{y}, @var{z})
22 ## @deftypefnx {Function File} {} surface (@var{z}, @var{c})
23 ## @deftypefnx {Function File} {} surface (@var{z})
24 ## @deftypefnx {Function File} {} surface (@dots{}, @var{prop}, @var{val})
25 ## @deftypefnx {Function File} {} surface (@var{h}, @dots{})
26 ## @deftypefnx {Function File} {@var{h} =} surface (@dots{})
27 ## Plot a surface graphic object given matrices @var{x}, and @var{y} from
28 ## @code{meshgrid} and a matrix @var{z} corresponding to the @var{x} and
29 ## @var{y} coordinates of the surface. If @var{x} and @var{y} are vectors,
30 ## then a typical vertex is (@var{x}(j), @var{y}(i), @var{z}(i,j)). Thus,
31 ## columns of @var{z} correspond to different @var{x} values and rows of
32 ## @var{z} correspond to different @var{y} values. If @var{x} and @var{y}
33 ## are missing, they are constructed from size of the matrix @var{z}.
35 ## Any additional properties passed are assigned to the surface.
37 ## The optional return value @var{h} is a graphics handle to the created
39 ## @seealso{surf, mesh, patch, line}
44 function retval = surface (varargin)
46 [h, varargin] = __plt_get_axis_arg__ ("surface", varargin{:});
51 [tmp, bad_usage] = __surface__ (h, varargin{:});
52 unwind_protect_cleanup
66 function [h, bad_usage] = __surface__ (ax, varargin)
72 if (ischar (varargin{i - 1}))
80 elseif (firststring == 5)
86 [z_nr, z_nc] = size (z);
87 [c_nr, c_nc, c_np] = size (c);
88 if (! (z_nr == c_nr && z_nc == c_nc && (c_np == 1 || c_np == 3)))
89 error ("surface: Z and C must have the same size");
92 if (isvector (x) && isvector (y) && ismatrix (z))
93 if (rows (z) == length (y) && columns (z) == length (x))
97 error ("surface: rows (Z) must be the same as length (Y) and columns (Z) must be the same as length (X)");
99 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z))
100 if (! size_equal (x, y, z))
101 error ("surface: X, Y, and Z must have the same dimensions");
104 error ("surface: X and Y must be vectors and Z must be a matrix");
106 elseif (firststring == 4)
111 if (isvector (x) && isvector (y) && ismatrix (z))
112 if (rows (z) == length (y) && columns (z) == length (x))
116 error ("surface: rows (Z) must be the same as length (Y) and columns (Z) must be the same as length (X)");
118 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z))
119 if (! size_equal (x, y, z))
120 error ("surface: X, Y, and Z must have the same dimensions");
123 error ("surface: X and Y must be vectors and Z must be a matrix");
125 elseif (firststring == 3)
128 if (ismatrix (z) && !isvector (z) && !isscalar (z))
133 error ("surface: Z argument must be a matrix");
135 elseif (firststring == 2)
138 if (ismatrix (z) && !isvector (z) && !isscalar (z))
143 error ("surface: Z argument must be a matrix");
145 elseif (firststring == 1)
154 ## Make a default surface object.
156 if (firststring < nargin)
157 other_args = varargin(firststring:end);
159 h = __go_surface__ (ax, "xdata", x, "ydata", y, "zdata", z, "cdata", c,
163 set (ax, "view", [0, 90], "box", "off");
169 ## Functional tests for surface() are in surf.m, surfc.m, surfl.m, and pcolor.m
172 %! hf = figure ("visible", "off");
175 %! assert (findobj (hf, "type", "surface"), h);
176 %! assert (get (h, "xdata"), 1:3, eps);
177 %! assert (get (h, "ydata"), (1:3)', eps);
178 %! assert (get (h, "zdata"), eye(3));
179 %! assert (get (h, "cdata"), eye(3));
180 %! assert (get (h, "type"), "surface");
181 %! assert (get (h, "linestyle"), get (0, "defaultsurfacelinestyle"));
182 %! assert (get (h, "linewidth"), get (0, "defaultsurfacelinewidth"), eps);
183 %! assert (get (h, "marker"), get (0, "defaultsurfacemarker"));
184 %! assert (get (h, "markersize"), get (0, "defaultsurfacemarkersize"));
185 %! unwind_protect_cleanup
187 %! end_unwind_protect