diff scripts/plot/draw/fplot.m @ 26150:46757ec0bac2

fplot.m: Use try/catch to avoid errors with non-vectorized functions (bug #55134). * fplot.m: Attempt to calculate y0 inside a try/catch block. If the feval fails, then create a vectorized version of the function and try again to calculate y0.
author Rik <rik@octave.org>
date Thu, 29 Nov 2018 14:02:12 -0800
parents 23483673ba43
children af655eb15cdc
line wrap: on
line diff
--- a/scripts/plot/draw/fplot.m	Thu Nov 29 12:15:25 2018 -0800
+++ b/scripts/plot/draw/fplot.m	Thu Nov 29 14:02:12 2018 -0800
@@ -128,23 +128,27 @@
   if (n != 5)
     ## n was specified
     x0 = linspace (limits(1), limits(2), n/2 + 1)';
-    y0 = feval (fn, x0);
-    x = linspace (limits(1), limits(2), n)';
-    y = feval (fn, x);
   else
     x0 = linspace (limits(1), limits(2), 5)';
-    y0 = feval (fn, x0);
     n = 8;
-    x = linspace (limits(1), limits(2), n)';
-    y = feval (fn, x);
   endif
 
-  if (isscalar (y0))
-    warning ("fplot: FN is not a vectorized function which reduces performance");
+  try
+    y0 = feval (fn, x0);
+    if (isscalar (y0))
+      warning ("fplot: FN is not a vectorized function which reduces performance");
+      fn = @(x) arrayfun (fn, x);  # Create a new fn that accepts vectors
+      y0 = feval (fn, x0);
+    endif
+  catch
+    ## feval failed, maybe it is because the function is not vectorized?
     fn = @(x) arrayfun (fn, x);  # Create a new fn that accepts vectors
     y0 = feval (fn, x0);
-    y = feval (fn, x);
-  endif
+    warning ("fplot: FN is not a vectorized function which reduces performance");
+  end_try_catch
+
+  x = linspace (limits(1), limits(2), n)';
+  y = feval (fn, x);
 
   if (rows (x0) == rows (y0))
     fcn_transpose = false;