Mercurial > hg > octave-nkf
comparison scripts/plot/surface.m @ 16986:df66488b8d43
surface.m: Validate inputs are not complex.
* scripts/plot/surface.m: Validate inputs are not complex.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 14 Jul 2013 16:00:26 -0700 |
parents | 5d3a684236b0 |
children | 55b76fd1244b |
comparison
equal
deleted
inserted
replaced
16985:c9346014fed2 | 16986:df66488b8d43 |
---|---|
39 ## @seealso{surf, mesh, patch, line} | 39 ## @seealso{surf, mesh, patch, line} |
40 ## @end deftypefn | 40 ## @end deftypefn |
41 | 41 |
42 ## Author: jwe | 42 ## Author: jwe |
43 | 43 |
44 function retval = surface (varargin) | 44 function h = surface (varargin) |
45 | 45 |
46 [h, varargin] = __plt_get_axis_arg__ ("surface", varargin{:}); | 46 [hax, varargin] = __plt_get_axis_arg__ ("surface", varargin{:}); |
47 | 47 |
48 oldh = gca (); | 48 oldax = gca (); |
49 unwind_protect | 49 unwind_protect |
50 axes (h); | 50 axes (hax); |
51 [tmp, bad_usage] = __surface__ (h, varargin{:}); | 51 [htmp, bad_usage] = __surface__ (hax, varargin{:}); |
52 unwind_protect_cleanup | 52 unwind_protect_cleanup |
53 axes (oldh); | 53 axes (oldax); |
54 end_unwind_protect | 54 end_unwind_protect |
55 | 55 |
56 if (bad_usage) | 56 if (bad_usage) |
57 print_usage (); | 57 print_usage (); |
58 endif | 58 endif |
59 | 59 |
60 if (nargout > 0) | 60 if (nargout > 0) |
61 retval = tmp; | 61 h = htmp; |
62 endif | 62 endif |
63 | 63 |
64 endfunction | 64 endfunction |
65 | 65 |
66 function [h, bad_usage] = __surface__ (ax, varargin) | 66 function [h, bad_usage] = __surface__ (ax, varargin) |
67 | 67 |
68 h = 0; | |
68 bad_usage = false; | 69 bad_usage = false; |
69 h = 0; | |
70 firststring = nargin; | 70 firststring = nargin; |
71 for i = 2 : nargin | 71 for i = 1 : (nargin - 1) |
72 if (ischar (varargin{i - 1})) | 72 if (ischar (varargin{i})) |
73 firststring = i - 1; | 73 firststring = i; |
74 break; | 74 break; |
75 endif | 75 endif |
76 endfor | 76 endfor |
77 | 77 |
78 if (firststring > 5) | 78 if (firststring > 5) |
79 bad_usage = true; | 79 bad_usage = true; |
80 return; | |
80 elseif (firststring == 5) | 81 elseif (firststring == 5) |
81 x = varargin{1}; | 82 x = varargin{1}; |
82 y = varargin{2}; | 83 y = varargin{2}; |
83 z = varargin{3}; | 84 z = varargin{3}; |
84 c = varargin{4}; | 85 c = varargin{4}; |
86 | |
87 if (iscomplex (x) || iscomplex (y) || iscomplex (z) || iscomplex (c)) | |
88 error ("mesh: X, Y, Z, C arguments must be real"); | |
89 endif | |
85 | 90 |
86 [z_nr, z_nc] = size (z); | 91 [z_nr, z_nc] = size (z); |
87 [c_nr, c_nc, c_np] = size (c); | 92 [c_nr, c_nc, c_np] = size (c); |
88 if (! (z_nr == c_nr && z_nc == c_nc && (c_np == 1 || c_np == 3))) | 93 if (! (z_nr == c_nr && z_nc == c_nc && (c_np == 1 || c_np == 3))) |
89 error ("surface: Z and C must have the same size"); | 94 error ("surface: Z and C must have the same size"); |
106 elseif (firststring == 4) | 111 elseif (firststring == 4) |
107 x = varargin{1}; | 112 x = varargin{1}; |
108 y = varargin{2}; | 113 y = varargin{2}; |
109 z = varargin{3}; | 114 z = varargin{3}; |
110 c = z; | 115 c = z; |
116 | |
117 if (iscomplex (x) || iscomplex (y) || iscomplex (z)) | |
118 error ("mesh: X, Y, Z arguments must be real"); | |
119 endif | |
120 | |
111 if (isvector (x) && isvector (y) && ismatrix (z)) | 121 if (isvector (x) && isvector (y) && ismatrix (z)) |
112 if (rows (z) == length (y) && columns (z) == length (x)) | 122 if (rows (z) == length (y) && columns (z) == length (x)) |
113 x = x(:)'; | 123 x = x(:)'; |
114 y = y(:); | 124 y = y(:); |
115 else | 125 else |
123 error ("surface: X and Y must be vectors and Z must be a matrix"); | 133 error ("surface: X and Y must be vectors and Z must be a matrix"); |
124 endif | 134 endif |
125 elseif (firststring == 3) | 135 elseif (firststring == 3) |
126 z = varargin{1}; | 136 z = varargin{1}; |
127 c = varargin{2}; | 137 c = varargin{2}; |
138 | |
139 if (iscomplex (z) || iscomplex (c)) | |
140 error ("mesh: X, C arguments must be real"); | |
141 endif | |
142 | |
128 if (ismatrix (z) && !isvector (z) && !isscalar (z)) | 143 if (ismatrix (z) && !isvector (z) && !isscalar (z)) |
129 [nr, nc] = size (z); | 144 [nr, nc] = size (z); |
130 x = 1:nc; | 145 x = 1:nc; |
131 y = (1:nr)'; | 146 y = (1:nr)'; |
132 else | 147 else |
133 error ("surface: Z argument must be a matrix"); | 148 error ("surface: Z argument must be a matrix"); |
134 endif | 149 endif |
135 elseif (firststring == 2) | 150 elseif (firststring == 2) |
136 z = varargin{1}; | 151 z = varargin{1}; |
137 c = z; | 152 c = z; |
153 | |
154 if (iscomplex (z)) | |
155 error ("mesh: Z argument must be real"); | |
156 endif | |
157 | |
138 if (ismatrix (z) && !isvector (z) && !isscalar (z)) | 158 if (ismatrix (z) && !isvector (z) && !isscalar (z)) |
139 [nr, nc] = size (z); | 159 [nr, nc] = size (z); |
140 x = 1:nc; | 160 x = 1:nc; |
141 y = (1:nr)'; | 161 y = (1:nr)'; |
142 else | 162 else |
143 error ("surface: Z argument must be a matrix"); | 163 error ("surface: Z argument must be a matrix"); |
144 endif | 164 endif |
145 elseif (firststring == 1) | 165 elseif (firststring == 1) |
146 x = 1:3; | 166 x = 1:3; |
147 y = (x).'; | 167 y = x'; |
148 c = z = eye (3); | 168 c = z = eye (3); |
149 else | 169 else |
150 bad_usage = true; | 170 bad_usage = true; |
151 endif | 171 return; |
152 | 172 endif |
153 if (! bad_usage) | 173 |
154 ## Make a default surface object. | 174 if (firststring < nargin) |
155 other_args = {}; | 175 other_args = varargin(firststring:end); |
156 if (firststring < nargin) | 176 else |
157 other_args = varargin(firststring:end); | 177 other_args = {}; # make a default surface object. |
158 endif | 178 endif |
159 h = __go_surface__ (ax, "xdata", x, "ydata", y, "zdata", z, "cdata", c, | 179 h = __go_surface__ (ax, "xdata", x, "ydata", y, "zdata", z, "cdata", c, |
160 other_args{:}); | 180 other_args{:}); |
161 | 181 |
162 if (! ishold ()) | 182 if (! ishold ()) |
163 set (ax, "view", [0, 90], "box", "off"); | 183 set (ax, "view", [0, 90], "box", "off"); |
164 endif | |
165 endif | 184 endif |
166 | 185 |
167 endfunction | 186 endfunction |
168 | 187 |
169 | 188 |