[英]Matlab fplot: not enough input arguments
我刚刚开始学习 Matlab,我一直在寻找解决方案。
基本上,我只需要 fplot 一个函数,然后对以后的问题进行更多操作。
fplot(@(x) myfunc);
function y = myfunc(x)
y = (x^3) - (4 .* x^2) - 1
end
产生这个错误
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.
当我单独使用 fplot 时它会起作用。
fplot((x^3)-(4*x^2)-1)
如果有人能指出我做错了什么,我将不胜感激。 我需要将它定义为函数的原因是因为我稍后需要对其进行更多操作。
您调用 fplot 的语法是问题所在,而不是您的函数。 如果您要传递一个简单的函数句柄,只需使用:
fplot(@myfunc)
您使用的语法是您创建匿名函数的方式,但您忘记在等式中包含x
。 你也可以这样写并得到相同的结果:
fplot(@(x) myfunc(x))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.