comparison scripts/plot/private/__ezplot__.m @ 10549:95c3e38098bf

Untabify .m scripts
author Rik <code@nomad.inbox5.com>
date Fri, 23 Apr 2010 11:28:50 -0700
parents 1aeb39118764
children c9b0a75b02e8
comparison
equal deleted inserted replaced
10548:479536c5bb10 10549:95c3e38098bf
74 endif 74 endif
75 fstr = formula (fun); 75 fstr = formula (fun);
76 if (isplot) 76 if (isplot)
77 xarg = argnames(fun){1}; 77 xarg = argnames(fun){1};
78 if (nargs == 2) 78 if (nargs == 2)
79 yarg = argnames(fun){2}; 79 yarg = argnames(fun){2};
80 else 80 else
81 yarg = ""; 81 yarg = "";
82 endif 82 endif
83 elseif (isplot3) 83 elseif (isplot3)
84 xarg = "x"; 84 xarg = "x";
85 yarg = "y"; 85 yarg = "y";
86 elseif (ispolar) 86 elseif (ispolar)
99 fun = vectorize (fun); 99 fun = vectorize (fun);
100 fstr = formula (fun); 100 fstr = formula (fun);
101 if (isplot) 101 if (isplot)
102 xarg = argnames(fun){1}; 102 xarg = argnames(fun){1};
103 if (nargs == 2) 103 if (nargs == 2)
104 yarg = argnames(fun){2}; 104 yarg = argnames(fun){2};
105 else 105 else
106 yarg = ""; 106 yarg = "";
107 endif 107 endif
108 elseif (isplot3) 108 elseif (isplot3)
109 xarg = "x"; 109 xarg = "x";
110 yarg = "y"; 110 yarg = "y";
111 elseif (isplot || ispolar) 111 elseif (isplot || ispolar)
117 endif 117 endif
118 elseif (isa (fun, "function_handle")) 118 elseif (isa (fun, "function_handle"))
119 fstr = func2str (fun); 119 fstr = func2str (fun);
120 if (length (findstr (fstr, ")")) != 0) 120 if (length (findstr (fstr, ")")) != 0)
121 args = regexp (substr (fstr, 3, findstr (fstr, ")")(1) - 3), 121 args = regexp (substr (fstr, 3, findstr (fstr, ")")(1) - 3),
122 '(\w[\w\d]*)', 'tokens'); 122 '(\w[\w\d]*)', 'tokens');
123 fstr = substr (fstr, findstr (fstr, ")")(1) + 1); 123 fstr = substr (fstr, findstr (fstr, ")")(1) + 1);
124 else 124 else
125 args = {{"x"}}; 125 args = {{"x"}};
126 endif 126 endif
127 if (isplot && length (args) == 2) 127 if (isplot && length (args) == 2)
130 error ("%s: excepting a function of %d arguments", func, nargs); 130 error ("%s: excepting a function of %d arguments", func, nargs);
131 endif 131 endif
132 if (isplot) 132 if (isplot)
133 xarg = args{1}{1}; 133 xarg = args{1}{1};
134 if (nargs == 2) 134 if (nargs == 2)
135 yarg = args{2}{1}; 135 yarg = args{2}{1};
136 else 136 else
137 yarg = ""; 137 yarg = "";
138 endif 138 endif
139 elseif (isplot3) 139 elseif (isplot3)
140 xarg = "x"; 140 xarg = "x";
141 yarg = "y"; 141 yarg = "y";
142 elseif (ispolar) 142 elseif (ispolar)
155 fstrx = fstr; 155 fstrx = fstr;
156 funy = varargin {2}; 156 funy = varargin {2};
157 if (ischar (funy) && ! strcmp (funy, "circ") && ! strcmp (funy, "animate")) 157 if (ischar (funy) && ! strcmp (funy, "circ") && ! strcmp (funy, "animate"))
158 parametric = true; 158 parametric = true;
159 if (exist (funy, "file") || exist (funy, "builtin")) 159 if (exist (funy, "file") || exist (funy, "builtin"))
160 funy = vectorize (inline (cstrcat (funy, "(t)"))); 160 funy = vectorize (inline (cstrcat (funy, "(t)")));
161 else 161 else
162 funy = vectorize (inline (funy)); 162 funy = vectorize (inline (funy));
163 endif 163 endif
164 if (length (argnames (funy)) != nargs) 164 if (length (argnames (funy)) != nargs)
165 error ("%s: excepting a function of %d arguments", func, nargs); 165 error ("%s: excepting a function of %d arguments", func, nargs);
166 endif 166 endif
167 fstry = formula (funy); 167 fstry = formula (funy);
168 elseif (strcmp (typeinfo (funy), "inline function")) 168 elseif (strcmp (typeinfo (funy), "inline function"))
169 parametric = true; 169 parametric = true;
170 if (length (argnames (funy)) != nargs) 170 if (length (argnames (funy)) != nargs)
171 error ("%s: excepting a function of %d arguments", func, nargs); 171 error ("%s: excepting a function of %d arguments", func, nargs);
172 endif 172 endif
173 funy = vectorize (funy); 173 funy = vectorize (funy);
174 fstry = formula (funy); 174 fstry = formula (funy);
175 elseif (isa (funy, "function_handle")) 175 elseif (isa (funy, "function_handle"))
176 parametric = true; 176 parametric = true;
177 fstry = func2str (funy); 177 fstry = func2str (funy);
178 if (length (findstr (fstry, ")")) != 0) 178 if (length (findstr (fstry, ")")) != 0)
179 args = regexp (substr (fstry, 3, findstr (fstry, ")")(1) - 3), 179 args = regexp (substr (fstry, 3, findstr (fstry, ")")(1) - 3),
180 '(\w[\w\d]*)', 'tokens'); 180 '(\w[\w\d]*)', 'tokens');
181 fstry = substr (fstry, findstr (fstry, ")")(1) + 1); 181 fstry = substr (fstry, findstr (fstry, ")")(1) + 1);
182 else 182 else
183 args = {{"y"}}; 183 args = {{"y"}};
184 endif 184 endif
185 if (length (args) != nargs) 185 if (length (args) != nargs)
186 error ("%s: excepting a function of %d arguments", func, nargs); 186 error ("%s: excepting a function of %d arguments", func, nargs);
187 endif 187 endif
188 endif 188 endif
189 189
190 if (parametric && isplot) 190 if (parametric && isplot)
191 xarg = "x"; 191 xarg = "x";
192 yarg = "y"; 192 yarg = "y";
193 if (nargs == 2) 193 if (nargs == 2)
194 error ("%s: can not define a parametric function in this manner"); 194 error ("%s: can not define a parametric function in this manner");
195 endif 195 endif
196 endif 196 endif
197 197
198 if (!isplot && parametric) 198 if (!isplot && parametric)
199 funz = varargin {3}; 199 funz = varargin {3};
200 if (ischar (funz) && ! strcmp (funz, "circ") && 200 if (ischar (funz) && ! strcmp (funz, "circ") &&
201 ! strcmp (funz, "animate")) 201 ! strcmp (funz, "animate"))
202 if (exist (funz, "file") || exist (funz, "builtin")) 202 if (exist (funz, "file") || exist (funz, "builtin"))
203 funz = vectorize (inline (cstrcat (funz, "(t)"))); 203 funz = vectorize (inline (cstrcat (funz, "(t)")));
204 else 204 else
205 funz = vectorize (inline (funz)); 205 funz = vectorize (inline (funz));
206 endif 206 endif
207 if (length (argnames (funz)) != nargs) 207 if (length (argnames (funz)) != nargs)
208 error ("%s: excepting a function of %d arguments", func, nargs); 208 error ("%s: excepting a function of %d arguments", func, nargs);
209 endif 209 endif
210 fstrz = formula (funz); 210 fstrz = formula (funz);
211 elseif (strcmp (typeinfo (funz), "inline function")) 211 elseif (strcmp (typeinfo (funz), "inline function"))
212 if (length (argnames (funz)) != nargs) 212 if (length (argnames (funz)) != nargs)
213 error ("%s: excepting a function of %d arguments", func, nargs); 213 error ("%s: excepting a function of %d arguments", func, nargs);
214 endif 214 endif
215 funz = vectorize (funz); 215 funz = vectorize (funz);
216 fstrz = formula (funz); 216 fstrz = formula (funz);
217 elseif (isa (funz, "function_handle")) 217 elseif (isa (funz, "function_handle"))
218 fstrz = func2str (funz); 218 fstrz = func2str (funz);
219 args = regexp (substr (fstrz, 3, findstr (fstrz, ")")(1) - 3), 219 args = regexp (substr (fstrz, 3, findstr (fstrz, ")")(1) - 3),
220 '(\w[\w\d]*)', 'tokens'); 220 '(\w[\w\d]*)', 'tokens');
221 if (length (args) != nargs) 221 if (length (args) != nargs)
222 error ("%s: excepting a function of %d arguments", func, nargs); 222 error ("%s: excepting a function of %d arguments", func, nargs);
223 endif 223 endif
224 fstrz = substr (fstrz, findstr (fstrz, ")")(1) + 1); 224 fstrz = substr (fstrz, findstr (fstrz, ")")(1) + 1);
225 else 225 else
226 error ("%s: parametric plots expect 3 functions", func); 226 error ("%s: parametric plots expect 3 functions", func);
227 endif 227 endif
228 endif 228 endif
229 endif 229 endif
230 230
231 if (isplot && nargs != 2) 231 if (isplot && nargs != 2)
275 needusage = true; 275 needusage = true;
276 return; 276 return;
277 endif 277 endif
278 if (parametric) 278 if (parametric)
279 error ("%s: can not have both circular domain and parametric function", 279 error ("%s: can not have both circular domain and parametric function",
280 func); 280 func);
281 endif 281 endif
282 cent = [domain(1) + domain(2), domain(3) + domain(4)] / 2; 282 cent = [domain(1) + domain(2), domain(3) + domain(4)] / 2;
283 funx = @(r,t) r .* cos (t) + cent (1); 283 funx = @(r,t) r .* cos (t) + cent (1);
284 funy = @(r,t) r .* sin (t) + cent (2); 284 funy = @(r,t) r .* sin (t) + cent (2);
285 domain = [0, sqrt((domain(2) - cent(1))^2 + (domain(4) - cent(2))^2), ... 285 domain = [0, sqrt((domain(2) - cent(1))^2 + (domain(4) - cent(2))^2), ...
286 -pi, pi]; 286 -pi, pi];
287 funz = fun; 287 funz = fun;
288 parametric = true; 288 parametric = true;
289 endif 289 endif
290 290
291 if (animate) 291 if (animate)
329 Y = __eliminate_sing__ (Y); 329 Y = __eliminate_sing__ (Y);
330 Z = __eliminate_sing__ (Z); 330 Z = __eliminate_sing__ (Z);
331 endif 331 endif
332 332
333 fstrx = regexprep (regexprep (regexprep (fstrx,'\.\^\s*','^'), 333 fstrx = regexprep (regexprep (regexprep (fstrx,'\.\^\s*','^'),
334 '\./', '/'), '[\.]*\*', ''); 334 '\./', '/'), '[\.]*\*', '');
335 fstry = regexprep (regexprep (regexprep (fstry,'\.\^\s*','^'), 335 fstry = regexprep (regexprep (regexprep (fstry,'\.\^\s*','^'),
336 '\./', '/'), '[\.]*\*', ''); 336 '\./', '/'), '[\.]*\*', '');
337 if (isplot) 337 if (isplot)
338 fstr = cstrcat ("x = ",fstrx,", y = ",fstry); 338 fstr = cstrcat ("x = ",fstrx,", y = ",fstry);
339 else 339 else
340 fstrz = regexprep (regexprep (regexprep (fstrz,'\.\^\s*','^'), 340 fstrz = regexprep (regexprep (regexprep (fstrz,'\.\^\s*','^'),
341 '\./', '/'), '[\.]*\*', ''); 341 '\./', '/'), '[\.]*\*', '');
342 fstr = cstrcat ("x = ",fstrx,",y = ",fstry,", z = ",fstrz); 342 fstr = cstrcat ("x = ",fstrx,",y = ",fstry,", z = ",fstrz);
343 endif 343 endif
344 else 344 else
345 if (isplot3) 345 if (isplot3)
346 needusage = true; 346 needusage = true;
347 return; 347 return;
348 endif 348 endif
349 349
350 fstr = regexprep (regexprep (regexprep (fstr,'\.\^\s*','^'), '\./', '/'), 350 fstr = regexprep (regexprep (regexprep (fstr,'\.\^\s*','^'), '\./', '/'),
351 '[\.]*\*', ''); 351 '[\.]*\*', '');
352 if (isplot && nargs == 2) 352 if (isplot && nargs == 2)
353 if (strcmp (typeinfo (fun), "inline function") && 353 if (strcmp (typeinfo (fun), "inline function") &&
354 !isempty (strfind (formula (fun) , "="))) 354 !isempty (strfind (formula (fun) , "=")))
355 fun = inline (cstrcat (strrep (formula (fun), "=", "- ("), ")")); 355 fun = inline (cstrcat (strrep (formula (fun), "=", "- ("), ")"));
356 else 356 else
357 fstr = cstrcat (fstr, " = 0"); 357 fstr = cstrcat (fstr, " = 0");
358 endif 358 endif
359 359
360 Z = feval (fun, X, Y); 360 Z = feval (fun, X, Y);
361 361
362 ## Matlab returns line objects for this case and so can't call 362 ## Matlab returns line objects for this case and so can't call
367 367
368 i1 = 1; 368 i1 = 1;
369 XX = {}; 369 XX = {};
370 YY = {}; 370 YY = {};
371 while (i1 < length (c)) 371 while (i1 < length (c))
372 clev = c(1,i1); 372 clev = c(1,i1);
373 clen = c(2,i1); 373 clen = c(2,i1);
374 XX = [XX, {c(1, i1+1:i1+clen)}]; 374 XX = [XX, {c(1, i1+1:i1+clen)}];
375 YY = [YY, {c(2, i1+1:i1+clen)}]; 375 YY = [YY, {c(2, i1+1:i1+clen)}];
376 i1 += clen+1; 376 i1 += clen+1;
377 endwhile 377 endwhile
378 else 378 else
379 if (ispolar) 379 if (ispolar)
380 Z = feval (fun, X); 380 Z = feval (fun, X);
381 elseif (isplot) 381 elseif (isplot)
382 Z = real (feval (fun, X)); 382 Z = real (feval (fun, X));
383 383
384 ## Eliminate the singularities. This seems to be what matlab 384 ## Eliminate the singularities. This seems to be what matlab
385 ## does, but can't be sure. 385 ## does, but can't be sure.
386 XX = sort (Z (isfinite (Z))); 386 XX = sort (Z (isfinite (Z)));
387 if (length (X) > 4) 387 if (length (X) > 4)
388 d = XX(fix (7 * length (XX) / 8)) - XX(fix (length (XX) / 8)); 388 d = XX(fix (7 * length (XX) / 8)) - XX(fix (length (XX) / 8));
389 yrange = [max(XX(1) - d/8, XX(fix (length (XX) / 8)) - d), ... 389 yrange = [max(XX(1) - d/8, XX(fix (length (XX) / 8)) - d), ...
390 min(XX(end) + d/8, XX(fix (7 * length (XX) / 8)) + d)]; 390 min(XX(end) + d/8, XX(fix (7 * length (XX) / 8)) + d)];
391 else 391 else
392 yrange = [XX(1), XX(end)]; 392 yrange = [XX(1), XX(end)];
393 endif 393 endif
394 394
395 idx = 2 : length(Z); 395 idx = 2 : length(Z);
396 idx = find (((Z(idx) > yrange(2) / 2) & (Z(idx-1) < yrange(1) / 2)) | 396 idx = find (((Z(idx) > yrange(2) / 2) & (Z(idx-1) < yrange(1) / 2)) |
397 ((Z(idx) < yrange(1) / 2) & (Z(idx-1) > yrange (2) / 2))); 397 ((Z(idx) < yrange(1) / 2) & (Z(idx-1) > yrange (2) / 2)));
398 if (any(idx)) 398 if (any(idx))
399 Z(idx) = NaN; 399 Z(idx) = NaN;
400 endif 400 endif
401 else 401 else
402 Z = feval (fun, X, Y); 402 Z = feval (fun, X, Y);
403 403
404 ## Eliminate the singularities 404 ## Eliminate the singularities
405 Z = __eliminate_sing__ (Z); 405 Z = __eliminate_sing__ (Z);
406 endif 406 endif
407 endif 407 endif
408 endif 408 endif
409 409
410 oldax = gca (); 410 oldax = gca ();
414 [clev, h] = feval (pfunc, X, Y, Z); 414 [clev, h] = feval (pfunc, X, Y, Z);
415 elseif (isplot && nargs == 2) 415 elseif (isplot && nargs == 2)
416 h = []; 416 h = [];
417 hold_state = get (ax, "nextplot"); 417 hold_state = get (ax, "nextplot");
418 for i = 1 : length (XX) 418 for i = 1 : length (XX)
419 h = [h; plot(XX{i}, YY{i})]; 419 h = [h; plot(XX{i}, YY{i})];
420 if (i == 1) 420 if (i == 1)
421 set (ax, "nextplot", "add") 421 set (ax, "nextplot", "add")
422 endif 422 endif
423 endfor 423 endfor
424 set (ax, "nextplot", hold_state) 424 set (ax, "nextplot", hold_state)
425 elseif (ispolar || isplot) 425 elseif (ispolar || isplot)
426 h = feval (pfunc, X, Z); 426 h = feval (pfunc, X, Z);
427 if (isplot && !parametric) 427 if (isplot && !parametric)
428 axis ([X(1), X(end), yrange]); 428 axis ([X(1), X(end), yrange]);
429 endif 429 endif
430 else 430 else
431 h = feval (pfunc, X, Y, Z); 431 h = feval (pfunc, X, Y, Z);
432 endif 432 endif
433 xlabel (xarg); 433 xlabel (xarg);