1

I'm just starting to learn Matlab, and I've been searching around a lot for a solution.

Basically, I just need to fplot a function and then manipulate it more for later questions.

fplot(@(x) myfunc);

function y = myfunc(x)
    y = (x^3) - (4 .* x^2) - 1
end

Produces this error

Warning: Function behaves unexpectedly on array inputs. To improve performance,
properly vectorize your function to return an output with the same size and shape as
the input arguments. 
> In matlab.graphics.function.FunctionLine>getFunction
  In matlab.graphics.function.FunctionLine/updateFunction
  In matlab.graphics.function.FunctionLine/set.Function_I
  In matlab.graphics.function.FunctionLine/set.Function
  In matlab.graphics.function.FunctionLine
  In fplot>singleFplot (line 234)
  In fplot>@(f)singleFplot(cax,{f},limits,extraOpts,args) (line 193)
  In fplot>vectorizeFplot (line 193)
  In fplot (line 163)
  In HWA1_2 (line 1) 
Warning: Error updating FunctionLine.

 The following error was reported evaluating the function in FunctionLine update: Not
 enough input arguments.

It works when I just use fplot on its own.

fplot((x^3)-(4*x^2)-1)

If anyone could point out what I'm doing wrong I'd be very grateful. The reason I need it defined as a function is because I need to do more manipulations to it later on.

1 Answer 1

2

Your syntax for calling fplot is the problem, not your function. If you're passing a simple function handle, just use:

fplot(@myfunc)

The syntax you were using is how you'd create an anonymous function, but you forgot to include x in the equation. You could also write it like this and get the same result:

fplot(@(x) myfunc(x))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.