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