error while using ezplot

19 views (last 30 days)
math search
math search on 6 Jun 2014
Answered: Walter Roberson on 25 Jun 2016
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?

Answers (4)

Geoff Hayes
Geoff Hayes on 6 Jun 2014
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 on 6 Jun 2014
I have never used those toolboxes. Just trying to learn some basic info and thank you for the interest.

gh y
gh y on 25 Jun 2016
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 on 25 Jun 2016
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

Categories

Find more on Function Creation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!