Mercurial > hg > octave-lyh
annotate scripts/plot/surface.m @ 11587:c792872f8942
all script files: untabify and strip trailing whitespace
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 20 Jan 2011 17:35:29 -0500 |
parents | fd0a3ac60b0e |
children | e3e6079039c6 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1993-2011 John W. Eaton |
7109 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
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. | |
9 ## | |
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. | |
14 ## | |
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/>. | |
18 | |
19 ## -*- texinfo -*- | |
10634
60542efcfa2c
Check input arguments for size and type (bug #29861).
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
20 ## @deftypefn {Function File} {} surface (@var{x}, @var{y}, @var{z}, @var{c}) |
7175 | 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{}) | |
7650 | 26 ## @deftypefnx {Function File} {@var{h} =} surface (@dots{}) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
27 ## Plot a surface graphic object given matrices @var{x}, and @var{y} from |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
28 ## @code{meshgrid} and a matrix @var{z} corresponding to the @var{x} and |
7175 | 29 ## @var{y} coordinates of the surface. If @var{x} and @var{y} are vectors, |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
30 ## then a typical vertex is (@var{x}(j), @var{y}(i), @var{z}(i,j)). Thus, |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
31 ## 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
|
32 ## @var{z} correspond to different @var{y} values. If @var{x} and @var{y} |
7175 | 33 ## are missing, they are constructed from size of the matrix @var{z}. |
34 ## | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
7650
diff
changeset
|
35 ## Any additional properties passed are assigned to the surface. |
7109 | 36 ## @seealso{surf, mesh, patch, line} |
37 ## @end deftypefn | |
38 | |
39 ## Author: jwe | |
40 | |
7216 | 41 function retval = surface (varargin) |
7109 | 42 |
7215 | 43 [h, varargin] = __plt_get_axis_arg__ ("surface", varargin{:}); |
44 | |
45 oldh = gca (); | |
46 unwind_protect | |
47 axes (h); | |
48 [tmp, bad_usage] = __surface__ (h, varargin{:}); | |
49 unwind_protect_cleanup | |
50 axes (oldh); | |
51 end_unwind_protect | |
7109 | 52 |
7207 | 53 if (bad_usage) |
54 print_usage (); | |
55 endif | |
56 | |
57 if (nargout > 0) | |
7216 | 58 retval = tmp; |
7207 | 59 endif |
7216 | 60 |
7207 | 61 endfunction |
62 | |
63 function [h, bad_usage] = __surface__ (ax, varargin) | |
64 | |
65 bad_usage = false; | |
66 h = 0; | |
67 firststring = nargin; | |
68 for i = 2 : nargin | |
7208 | 69 if (ischar (varargin{i - 1})) |
7207 | 70 firststring = i - 1; |
7175 | 71 break; |
7109 | 72 endif |
7175 | 73 endfor |
74 | |
75 if (firststring > 5) | |
7207 | 76 bad_usage = true; |
7175 | 77 elseif (firststring == 5) |
78 x = varargin{1}; | |
79 y = varargin{2}; | |
80 z = varargin{3}; | |
81 c = varargin{4}; | |
82 | |
7110 | 83 if (! size_equal (z, c)) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10634
diff
changeset
|
84 error ("surface: Z and C must have the same size"); |
7109 | 85 endif |
86 if (isvector (x) && isvector (y) && ismatrix (z)) | |
87 if (rows (z) == length (y) && columns (z) == length (x)) | |
88 x = x(:)'; | |
89 y = y(:); | |
90 else | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10634
diff
changeset
|
91 error ("surface: rows (Z) must be the same as length (Y) and columns (Z) must be the same as length (X)"); |
7109 | 92 endif |
93 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) | |
7292 | 94 if (! size_equal (x, y, z)) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10634
diff
changeset
|
95 error ("surface: X, Y, and Z must have the same dimensions"); |
7109 | 96 endif |
97 else | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10634
diff
changeset
|
98 error ("surface: X and Y must be vectors and Z must be a matrix"); |
7109 | 99 endif |
7175 | 100 elseif (firststring == 4) |
101 x = varargin{1}; | |
102 y = varargin{2}; | |
103 z = varargin{3}; | |
104 c = z; | |
105 if (isvector (x) && isvector (y) && ismatrix (z)) | |
106 if (rows (z) == length (y) && columns (z) == length (x)) | |
107 x = x(:)'; | |
108 y = y(:); | |
109 else | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10634
diff
changeset
|
110 error ("surface: rows (Z) must be the same as length (Y) and columns (Z) must be the same as length (X)"); |
7175 | 111 endif |
112 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) | |
7292 | 113 if (! size_equal (x, y, z)) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10634
diff
changeset
|
114 error ("surface: X, Y, and Z must have the same dimensions"); |
7175 | 115 endif |
116 else | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10634
diff
changeset
|
117 error ("surface: X and Y must be vectors and Z must be a matrix"); |
7175 | 118 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
119 elseif (firststring == 3) |
7208 | 120 z = varargin{1}; |
121 c = varargin{2}; | |
10634
60542efcfa2c
Check input arguments for size and type (bug #29861).
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
122 if (ismatrix (z) && !isvector (z) && !isscalar (z)) |
7175 | 123 [nr, nc] = size (z); |
124 x = 1:nc; | |
125 y = (1:nr)'; | |
126 else | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10634
diff
changeset
|
127 error ("surface: Z argument must be a matrix"); |
7175 | 128 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
129 elseif (firststring == 2) |
7208 | 130 z = varargin{1}; |
7175 | 131 c = z; |
10634
60542efcfa2c
Check input arguments for size and type (bug #29861).
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
132 if (ismatrix (z) && !isvector (z) && !isscalar (z)) |
7175 | 133 [nr, nc] = size (z); |
134 x = 1:nc; | |
135 y = (1:nr)'; | |
136 else | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10634
diff
changeset
|
137 error ("surface: Z argument must be a matrix"); |
7175 | 138 endif |
7109 | 139 else |
7207 | 140 bad_usage = true; |
7189 | 141 endif |
7109 | 142 |
7207 | 143 if (! bad_usage) |
144 ## Make a default surface object. | |
7277 | 145 other_args = {}; |
7207 | 146 if (firststring < nargin) |
7277 | 147 other_args = varargin(firststring:end); |
148 endif | |
149 h = __go_surface__ (ax, "xdata", x, "ydata", y, "zdata", z, "cdata", c, | |
10549 | 150 other_args{:}); |
7109 | 151 |
7277 | 152 if (! ishold ()) |
7298 | 153 set (ax, "view", [0, 90], "box", "off"); |
7277 | 154 endif |
155 endif | |
7109 | 156 |
157 endfunction |