comparison scripts/plot/fplot.m @ 10400:b14fd5116c29

Ensure that 'limits' is a 2 or 4 vector, and that 'fn' is a function
author Soren Hauberg <hauberg@gmail.com>
date Fri, 05 Mar 2010 14:29:47 -0800
parents 1bf0ce0930be
children 95c3e38098bf
comparison
equal deleted inserted replaced
10399:81bcdf5fd7a9 10400:b14fd5116c29
44 function fplot (fn, limits, n, linespec) 44 function fplot (fn, limits, n, linespec)
45 if (nargin < 2 || nargin > 4) 45 if (nargin < 2 || nargin > 4)
46 print_usage (); 46 print_usage ();
47 endif 47 endif
48 48
49 if (!isreal (limits) || (numel (limits) != 2 && numel (limits) != 4))
50 error ("fplot: second input argument must be a real vector with 2 or 4 elements");
51 endif
52
49 if (nargin < 3) 53 if (nargin < 3)
50 n = 0.002; 54 n = 0.002;
51 endif 55 endif
52 56
53 have_linespec = true; 57 have_linespec = true;
66 nam = formula (fn); 70 nam = formula (fn);
67 elseif (isa (fn, "function_handle")) 71 elseif (isa (fn, "function_handle"))
68 nam = func2str (fn); 72 nam = func2str (fn);
69 elseif (all (isalnum (fn))) 73 elseif (all (isalnum (fn)))
70 nam = fn; 74 nam = fn;
75 elseif (ischar (fn))
76 fn = vectorize (inline (fn));
77 nam = formula (fn);
71 else 78 else
72 fn = vectorize (inline (fn)); 79 error ("fplot: first input argument must be a function handle, inline function or string");
73 nam = formula (fn);
74 endif 80 endif
75 81
76 if (floor(n) != n) 82 if (floor(n) != n)
77 tol = n; 83 tol = n;
78 x0 = linspace (limits(1), limits(2), 5)'; 84 x0 = linspace (limits(1), limits(2), 5)';