error while using ezplot
13 次查看(过去 30 天)
显示 更早的评论
Hi, all.
d = x^2 –6*x – 12;
>> ezplot(d)
Error using inlineeval (line 15)
Error in inline expression ==> x.^2 –6.*x – 12
Error: The input character is not valid in MATLAB statements or
expressions.
Error in inline/feval (line 34)
INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr,
INLINE_OBJ_.expr);
Error in ezplotfeval (line 52)
z = feval(f,x(1));
Error in ezplot>ezplot1 (line 469)
[y, f, loopflag] = ezplotfeval(f, x);
Error in ezplot (line 145)
[hp, cax] = ezplot1(cax, f{1}, vars, labels, args{:});
what is the problem here?
0 个评论
回答(4 个)
Geoff Hayes
2014-6-6
The first input to ezplot must e a function handle or a string (see http://www.mathworks.com/help/matlab/ref/ezplot.html for details). Your variable d is neither - are you using the Symbolic Math Toolbox with a previous command like sym x in order to get that command to evaluate successfully?
I was able to plot this function as follows
d = 'x.^2 - 6*x - 12'
ezplot(d)
or as
func = @(x)x.^2 - 6*x - 12
ezplot(func)
Note the addition of the period at x.^2 so that func can evaluate an input vector rather than just single elements.
0 个评论
gh y
2016-6-25
Some versions of MATLAB can plot a function using ezplot(2014b) while another version(newer versions) cant plot the same code and encounters error. however I didnt test using dot before ^ but found out that same code coudnt be run in two different versions.
0 个评论
Walter Roberson
2016-6-25
The problem is that the inline function was defined using en-dash, char(8211), U+2013, instead of regular hyphen or minus, char(45), U+002d
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!