Mercurial > hg > octave-lyh
annotate scripts/plot/surface.m @ 9245:16f53d29049f
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 22 May 2009 10:46:00 -0400 |
parents | 1bf0ce0930be |
children | 95c3e38098bf |
rev | line source |
---|---|
7109 | 1 ## Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2002, 2004, |
9245 | 2 ## 2005, 2006, 2007, 2008, 2009 John W. Eaton |
7109 | 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{}) | |
7650 | 27 ## @deftypefnx {Function File} {@var{h} =} surface (@dots{}) |
7175 | 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, | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
9040
diff
changeset
|
31 ## then a typical vertex is (@var{x}(j), @var{y}(i), @var{z}(i,j)). Thus, |
7175 | 32 ## columns of @var{z} correspond to different @var{x} values and rows of |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
33 ## @var{z} correspond to different @var{y} values. If @var{x} and @var{y} |
7175 | 34 ## are missing, they are constructed from size of the matrix @var{z}. |
35 ## | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
7650
diff
changeset
|
36 ## Any additional properties passed are assigned to the surface. |
7109 | 37 ## @seealso{surf, mesh, patch, line} |
38 ## @end deftypefn | |
39 | |
40 ## Author: jwe | |
41 | |
7216 | 42 function retval = surface (varargin) |
7109 | 43 |
7215 | 44 [h, varargin] = __plt_get_axis_arg__ ("surface", varargin{:}); |
45 | |
46 oldh = gca (); | |
47 unwind_protect | |
48 axes (h); | |
49 [tmp, bad_usage] = __surface__ (h, varargin{:}); | |
50 unwind_protect_cleanup | |
51 axes (oldh); | |
52 end_unwind_protect | |
7109 | 53 |
7207 | 54 if (bad_usage) |
55 print_usage (); | |
56 endif | |
57 | |
58 if (nargout > 0) | |
7216 | 59 retval = tmp; |
7207 | 60 endif |
7216 | 61 |
7207 | 62 endfunction |
63 | |
64 function [h, bad_usage] = __surface__ (ax, varargin) | |
65 | |
66 bad_usage = false; | |
67 h = 0; | |
68 firststring = nargin; | |
69 for i = 2 : nargin | |
7208 | 70 if (ischar (varargin{i - 1})) |
7207 | 71 firststring = i - 1; |
7175 | 72 break; |
7109 | 73 endif |
7175 | 74 endfor |
75 | |
76 if (firststring > 5) | |
7207 | 77 bad_usage = true; |
7175 | 78 elseif (firststring == 5) |
79 x = varargin{1}; | |
80 y = varargin{2}; | |
81 z = varargin{3}; | |
82 c = varargin{4}; | |
83 | |
7110 | 84 if (! size_equal (z, c)) |
7109 | 85 error ("surface: z and c must have same size"); |
86 endif | |
87 if (isvector (x) && isvector (y) && ismatrix (z)) | |
88 if (rows (z) == length (y) && columns (z) == length (x)) | |
89 x = x(:)'; | |
90 y = y(:); | |
91 else | |
7114 | 92 error ("surface: rows (z) must be the same as length (y) and columns (z) must be the same as length (x)"); |
7109 | 93 endif |
94 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) | |
7292 | 95 if (! size_equal (x, y, z)) |
7109 | 96 error ("surface: x, y, and z must have same dimensions"); |
97 endif | |
98 else | |
99 error ("surface: x and y must be vectors and z must be a matrix"); | |
100 endif | |
7175 | 101 elseif (firststring == 4) |
102 x = varargin{1}; | |
103 y = varargin{2}; | |
104 z = varargin{3}; | |
105 c = z; | |
106 if (isvector (x) && isvector (y) && ismatrix (z)) | |
107 if (rows (z) == length (y) && columns (z) == length (x)) | |
108 x = x(:)'; | |
109 y = y(:); | |
110 else | |
111 error ("surface: rows (z) must be the same as length (y) and columns (z) must be the same as length (x)"); | |
112 endif | |
113 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) | |
7292 | 114 if (! size_equal (x, y, z)) |
7175 | 115 error ("surface: x, y, and z must have same dimensions"); |
116 endif | |
117 else | |
118 error ("surface: x and y must be vectors and z must be a matrix"); | |
119 endif | |
120 elseif (firststring == 3) | |
7208 | 121 z = varargin{1}; |
122 c = varargin{2}; | |
7175 | 123 if (ismatrix (z)) |
124 [nr, nc] = size (z); | |
125 x = 1:nc; | |
126 y = (1:nr)'; | |
127 else | |
128 error ("surface: argument must be a matrix"); | |
129 endif | |
130 elseif (firststring == 2) | |
7208 | 131 z = varargin{1}; |
7175 | 132 c = z; |
133 if (ismatrix (z)) | |
134 [nr, nc] = size (z); | |
135 x = 1:nc; | |
136 y = (1:nr)'; | |
137 else | |
138 error ("surface: argument must be a matrix"); | |
139 endif | |
7109 | 140 else |
7207 | 141 bad_usage = true; |
7189 | 142 endif |
7109 | 143 |
7207 | 144 if (! bad_usage) |
145 ## Make a default surface object. | |
7277 | 146 other_args = {}; |
7207 | 147 if (firststring < nargin) |
7277 | 148 other_args = varargin(firststring:end); |
149 endif | |
150 h = __go_surface__ (ax, "xdata", x, "ydata", y, "zdata", z, "cdata", c, | |
7293 | 151 other_args{:}); |
7109 | 152 |
7277 | 153 if (! ishold ()) |
7298 | 154 set (ax, "view", [0, 90], "box", "off"); |
7277 | 155 endif |
156 endif | |
7109 | 157 |
158 endfunction |