简体   繁体   English

Matlab fplot:没有足够的输入参数

[英]Matlab fplot: not enough input arguments

I'm just starting to learn Matlab, and I've been searching around a lot for a solution.我刚刚开始学习 Matlab,我一直在寻找解决方案。

Basically, I just need to fplot a function and then manipulate it more for later questions.基本上,我只需要 fplot 一个函数,然后对以后的问题进行更多操作。

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 时它会起作用。

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.您调用 fplot 的语法是问题所在,而不是您的函数。 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.您使用的语法是您创建匿名函数的方式,但您忘记在等式中包含x You could also write it like this and get the same result:你也可以这样写并得到相同的结果:

fplot(@(x) myfunc(x))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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