Mercurial > hg > octave-nkf
diff scripts/plot/surface.m @ 7175:5ff4da7bd2e7
[project @ 2007-11-14 20:36:48 by jwe]
author | jwe |
---|---|
date | Wed, 14 Nov 2007 20:36:48 +0000 |
parents | c7e5e638a8d0 |
children | e8d953d03f6a |
line wrap: on
line diff
--- a/scripts/plot/surface.m +++ b/scripts/plot/surface.m @@ -18,49 +18,48 @@ ## <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} @var{h} = {} surface (@var{x}, @var{y}, @var{z}, @var{c}) -## @deftypefnx {Function File} @var{h} = {} surface (@var{x}, @var{y}, @var{z}) -## Plot a surface graphic object given matrices @var{x}, and @var{y} from @code{meshgrid} and -## a matrix @var{z} corresponding to the @var{x} and @var{y} coordinates of -## the surface. If @var{x} and @var{y} are vectors, then a typical vertex -## is (@var{x}(j), @var{y}(i), @var{z}(i,j)). Thus, columns of @var{z} -## correspond to different @var{x} values and rows of @var{z} correspond -## to different @var{y} values. +## @deftypefn {Function File} {} surface (@var{x}, @var{y}, @var{z}, @var{c}) +## @deftypefnx {Function File} {} surface (@var{x}, @var{y}, @var{z}) +## @deftypefnx {Function File} {} surface (@var{z}, @var{c}) +## @deftypefnx {Function File} {} surface (@var{z}) +## @deftypefnx {Function File} {} surface (@dots{}, @var{prop}, @var{val}) +## @deftypefnx {Function File} {} surface (@var{h}, @dots{}) +## @deftypefnx {Function File} {@var{h} = } surface (@dots{}) +## Plot a surface graphic object given matrices @var{x}, and @var{y} from +## @code{meshgrid} and a matrix @var{z} corresponding to the @var{x} and +## @var{y} coordinates of the surface. If @var{x} and @var{y} are vectors, +## then a typical vertex is (@var{x}(j), @var{y}(i), @var{z}(i,j)). Thus, +## columns of @var{z} correspond to different @var{x} values and rows of +## @var{z} correspond to different @var{y} values. If @var{x} and @var{y} +## are missing, they are constructed from size of the matrix @var{z}. +## +## Any additional properties passed are assigned the the surface.. ## @seealso{surf, mesh, patch, line} ## @end deftypefn ## Author: jwe -function h = surface (x, y, z, c) +function h = surface (varargin) ax = gca (); - if (nargin == 1) - c = z = x; - if (ismatrix (z)) - [nr, nc] = size (z); - x = 1:nc; - y = (1:nr)'; - else - error ("surface: argument must be a matrix"); + firststring = nargin + 1; + for i = 1 : nargin + if (ischar (varargin {i})) + firststring = i; + break; endif - elseif (nargin == 3) - c = z; - if (isvector (x) && isvector (y) && ismatrix (z)) - if (rows (z) == length (y) && columns (z) == length (x)) - x = x(:)'; - y = y(:); - else - error ("surface: rows (z) must be the same as length (y) and columns (z) must be the same as length (x)"); - endif - elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) - if (! (size_equal (x, y) && size_equal (x, z))) - error ("surface: x, y, and z must have same dimensions"); - endif - else - error ("surface: x and y must be vectors and z must be a matrix"); - endif - elseif (nargin == 4) + endfor + + + if (firststring > 5) + print_usage (); + elseif (firststring == 5) + x = varargin{1}; + y = varargin{2}; + z = varargin{3}; + c = varargin{4}; + if (! size_equal (z, c)) error ("surface: z and c must have same size"); endif @@ -78,6 +77,45 @@ else error ("surface: x and y must be vectors and z must be a matrix"); endif + elseif (firststring == 4) + x = varargin{1}; + y = varargin{2}; + z = varargin{3}; + c = z; + if (isvector (x) && isvector (y) && ismatrix (z)) + if (rows (z) == length (y) && columns (z) == length (x)) + x = x(:)'; + y = y(:); + else + error ("surface: rows (z) must be the same as length (y) and columns (z) must be the same as length (x)"); + endif + elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) + if (! (size_equal (x, y) && size_equal (x, z))) + error ("surface: x, y, and z must have same dimensions"); + endif + else + error ("surface: x and y must be vectors and z must be a matrix"); + endif + elseif (firststring == 3) + z = varargin {1}; + c = varargin {2}; + if (ismatrix (z)) + [nr, nc] = size (z); + x = 1:nc; + y = (1:nr)'; + else + error ("surface: argument must be a matrix"); + endif + elseif (firststring == 2) + z = varargin {1}; + c = z; + if (ismatrix (z)) + [nr, nc] = size (z); + x = 1:nc; + y = (1:nr)'; + else + error ("surface: argument must be a matrix"); + endif else print_usage (); endif @@ -85,6 +123,7 @@ ## Make a default surface object. tmp = __go_surface__ (ax, "xdata", x, "ydata", y, "zdata", z, "cdata", c); set (tmp, "facecolor","flat"); + set (tmp, varargin {firststring:end}); if (! ishold ()) set (ax, "view", [0, 90], "box", "off", "xgrid", "on", "ygrid", "on", "zgrid", "on");