简体   繁体   中英

Matlab fplot: not enough input arguments

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.

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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM