comparison scripts/plot/draw/private/__ezplot__.m @ 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 4197fc428c7d
children
comparison
equal deleted inserted replaced
20533:19617a5b7202 20534:c0566df8cde3
69 69
70 parametric = false; 70 parametric = false;
71 fun = varargin{1}; 71 fun = varargin{1};
72 if (ischar (fun)) 72 if (ischar (fun))
73 if (exist (fun, "file") || exist (fun, "builtin")) 73 if (exist (fun, "file") || exist (fun, "builtin"))
74 fun = inline ([fun "(t)"]); 74 fun = str2func (fun); # convert to function handle
75 else 75 else
76 fun = vectorize (inline (fun)); 76 fun = vectorize (inline (fun)); # convert to inline function
77 endif 77 endif
78 argids = argnames (fun); 78 endif
79 if (isplot && length (argids) == 2) 79
80 nargs = 2; 80 if (strcmp (typeinfo (fun), "inline function"))
81 elseif (numel (argids) != nargs)
82 error ("%s: expecting a function of %d arguments", ezfunc, nargs);
83 endif
84 fstr = formula (fun);
85 if (isplot)
86 xarg = argids{1};
87 if (nargs == 2)
88 yarg = argids{2};
89 else
90 yarg = "";
91 endif
92 elseif (isplot3)
93 xarg = "x";
94 yarg = "y";
95 elseif (ispolar)
96 xarg = "";
97 yarg = "";
98 else
99 xarg = argids{1};
100 yarg = argids{2};
101 endif
102 elseif (strcmp (typeinfo (fun), "inline function"))
103 argids = argnames (fun); 81 argids = argnames (fun);
104 if (isplot && length (argids) == 2) 82 if (isplot && length (argids) == 2)
105 nargs = 2; 83 nargs = 2;
106 elseif (numel (argids) != nargs) 84 elseif (numel (argids) != nargs)
107 error ("%s: expecting a function of %d arguments", ezfunc, nargs); 85 error ("%s: expecting a function of %d arguments", ezfunc, nargs);
131 if (idx != 0) 109 if (idx != 0)
132 args = regexp (fstr(3:(idx-1)), '\w+', 'match'); 110 args = regexp (fstr(3:(idx-1)), '\w+', 'match');
133 fstr = fstr(idx+2:end); # remove '@(x) ' from string name 111 fstr = fstr(idx+2:end); # remove '@(x) ' from string name
134 else 112 else
135 args = {"x"}; 113 args = {"x"};
114 try
115 if (builtin ("nargin", fun) == 2)
116 args{2} = "y";
117 endif
118 end_try_catch
136 endif 119 endif
137 if (isplot && length (args) == 2) 120 if (isplot && length (args) == 2)
138 nargs = 2; 121 nargs = 2;
139 elseif (numel (args) != nargs) 122 elseif (numel (args) != nargs)
140 error ("%s: expecting a function of %d arguments", ezfunc, nargs); 123 error ("%s: expecting a function of %d arguments", ezfunc, nargs);