changeset 20534:c0566df8cde3 stable

Generate correct ezplot for 2-input functions (bug #46004). * __ezplot__.m: Convert string name of m-files or built-in functions to a function handle rather than an inline function. Eliminate 1/3rd of input processing that was for string inputs. Use nargin to find whether input function uses 2 inputs.
author Rik <rik@octave.org>
date Tue, 22 Sep 2015 04:15:51 -0700
parents 19617a5b7202
children caa5de39147e
files scripts/plot/draw/private/__ezplot__.m
diffstat 1 files changed, 10 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/draw/private/__ezplot__.m	Tue Sep 22 03:08:14 2015 -0700
+++ b/scripts/plot/draw/private/__ezplot__.m	Tue Sep 22 04:15:51 2015 -0700
@@ -71,35 +71,13 @@
   fun = varargin{1};
   if (ischar (fun))
     if (exist (fun, "file") || exist (fun, "builtin"))
-      fun = inline ([fun "(t)"]);
+      fun = str2func (fun);            # convert to function handle
     else
-      fun = vectorize (inline (fun));
-    endif
-    argids = argnames (fun);
-    if (isplot && length (argids) == 2)
-      nargs = 2;
-    elseif (numel (argids) != nargs)
-      error ("%s: expecting a function of %d arguments", ezfunc, nargs);
+      fun = vectorize (inline (fun));  # convert to inline function
     endif
-    fstr = formula (fun);
-    if (isplot)
-      xarg = argids{1};
-      if (nargs == 2)
-        yarg = argids{2};
-      else
-        yarg = "";
-      endif
-    elseif (isplot3)
-      xarg = "x";
-      yarg = "y";
-    elseif (ispolar)
-      xarg = "";
-      yarg = "";
-    else
-      xarg = argids{1};
-      yarg = argids{2};
-    endif
-  elseif (strcmp (typeinfo (fun), "inline function"))
+  endif
+
+  if (strcmp (typeinfo (fun), "inline function"))
     argids = argnames (fun);
     if (isplot && length (argids) == 2)
       nargs = 2;
@@ -133,6 +111,11 @@
       fstr = fstr(idx+2:end);  # remove '@(x) ' from string name
     else
       args = {"x"};
+      try
+        if (builtin ("nargin", fun) == 2)
+          args{2} = "y";
+        endif
+      end_try_catch
     endif
     if (isplot && length (args) == 2)
       nargs = 2;