Mercurial > octave-nkf
comparison scripts/plot/surface.m @ 10634:60542efcfa2c
Check input arguments for size and type (bug #29861).
Prevents segmentation fault with odd inputs.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 16 May 2010 18:28:59 -0700 |
parents | 95c3e38098bf |
children | 1740012184f9 |
comparison
equal
deleted
inserted
replaced
10633:d022061c288d | 10634:60542efcfa2c |
---|---|
16 ## You should have received a copy of the GNU General Public License | 16 ## You should have received a copy of the GNU General Public License |
17 ## along with Octave; see the file COPYING. If not, see | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | 18 ## <http://www.gnu.org/licenses/>. |
19 | 19 |
20 ## -*- texinfo -*- | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {} surface (@var{x}, @var{y}, @var{z}, @var{c}) | 21 ## @deftypefn {Function File} {} surface (@var{x}, @var{y}, @var{z}, @var{c}) |
22 ## @deftypefnx {Function File} {} surface (@var{x}, @var{y}, @var{z}) | 22 ## @deftypefnx {Function File} {} surface (@var{x}, @var{y}, @var{z}) |
23 ## @deftypefnx {Function File} {} surface (@var{z}, @var{c}) | 23 ## @deftypefnx {Function File} {} surface (@var{z}, @var{c}) |
24 ## @deftypefnx {Function File} {} surface (@var{z}) | 24 ## @deftypefnx {Function File} {} surface (@var{z}) |
25 ## @deftypefnx {Function File} {} surface (@dots{}, @var{prop}, @var{val}) | 25 ## @deftypefnx {Function File} {} surface (@dots{}, @var{prop}, @var{val}) |
26 ## @deftypefnx {Function File} {} surface (@var{h}, @dots{}) | 26 ## @deftypefnx {Function File} {} surface (@var{h}, @dots{}) |
80 y = varargin{2}; | 80 y = varargin{2}; |
81 z = varargin{3}; | 81 z = varargin{3}; |
82 c = varargin{4}; | 82 c = varargin{4}; |
83 | 83 |
84 if (! size_equal (z, c)) | 84 if (! size_equal (z, c)) |
85 error ("surface: z and c must have same size"); | 85 error ("surface: z and c must have the same size"); |
86 endif | 86 endif |
87 if (isvector (x) && isvector (y) && ismatrix (z)) | 87 if (isvector (x) && isvector (y) && ismatrix (z)) |
88 if (rows (z) == length (y) && columns (z) == length (x)) | 88 if (rows (z) == length (y) && columns (z) == length (x)) |
89 x = x(:)'; | 89 x = x(:)'; |
90 y = y(:); | 90 y = y(:); |
91 else | 91 else |
92 error ("surface: rows (z) must be the same as length (y) and columns (z) must be the same as length (x)"); | 92 error ("surface: rows (z) must be the same as length (y) and columns (z) must be the same as length (x)"); |
93 endif | 93 endif |
94 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) | 94 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) |
95 if (! size_equal (x, y, z)) | 95 if (! size_equal (x, y, z)) |
96 error ("surface: x, y, and z must have same dimensions"); | 96 error ("surface: x, y, and z must have the same dimensions"); |
97 endif | 97 endif |
98 else | 98 else |
99 error ("surface: x and y must be vectors and z must be a matrix"); | 99 error ("surface: x and y must be vectors and z must be a matrix"); |
100 endif | 100 endif |
101 elseif (firststring == 4) | 101 elseif (firststring == 4) |
110 else | 110 else |
111 error ("surface: rows (z) must be the same as length (y) and columns (z) must be the same as length (x)"); | 111 error ("surface: rows (z) must be the same as length (y) and columns (z) must be the same as length (x)"); |
112 endif | 112 endif |
113 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) | 113 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) |
114 if (! size_equal (x, y, z)) | 114 if (! size_equal (x, y, z)) |
115 error ("surface: x, y, and z must have same dimensions"); | 115 error ("surface: x, y, and z must have the same dimensions"); |
116 endif | 116 endif |
117 else | 117 else |
118 error ("surface: x and y must be vectors and z must be a matrix"); | 118 error ("surface: x and y must be vectors and z must be a matrix"); |
119 endif | 119 endif |
120 elseif (firststring == 3) | 120 elseif (firststring == 3) |
121 z = varargin{1}; | 121 z = varargin{1}; |
122 c = varargin{2}; | 122 c = varargin{2}; |
123 if (ismatrix (z)) | 123 if (ismatrix (z) && !isvector (z) && !isscalar (z)) |
124 [nr, nc] = size (z); | 124 [nr, nc] = size (z); |
125 x = 1:nc; | 125 x = 1:nc; |
126 y = (1:nr)'; | 126 y = (1:nr)'; |
127 else | 127 else |
128 error ("surface: argument must be a matrix"); | 128 error ("surface: z argument must be a matrix"); |
129 endif | 129 endif |
130 elseif (firststring == 2) | 130 elseif (firststring == 2) |
131 z = varargin{1}; | 131 z = varargin{1}; |
132 c = z; | 132 c = z; |
133 if (ismatrix (z)) | 133 if (ismatrix (z) && !isvector (z) && !isscalar (z)) |
134 [nr, nc] = size (z); | 134 [nr, nc] = size (z); |
135 x = 1:nc; | 135 x = 1:nc; |
136 y = (1:nr)'; | 136 y = (1:nr)'; |
137 else | 137 else |
138 error ("surface: argument must be a matrix"); | 138 error ("surface: z argument must be a matrix"); |
139 endif | 139 endif |
140 else | 140 else |
141 bad_usage = true; | 141 bad_usage = true; |
142 endif | 142 endif |
143 | 143 |