error while using ezplot

19 ビュー (過去 30 日間)
math search
math search 2014 年 6 月 6 日
回答済み: Walter Roberson 2016 年 6 月 25 日
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?

回答 (4 件)

Geoff Hayes
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.

math search
math search 2014 年 6 月 6 日
I have never used those toolboxes. Just trying to learn some basic info and thank you for the interest.

gh y
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.

Walter Roberson
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

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by