matlab - Matlab fplot:没有足够的输入参数
问题描述
我刚刚开始学习 Matlab,并且一直在寻找解决方案。
基本上,我只需要绘制一个函数,然后为以后的问题对其进行更多操作。
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))
推荐阅读
- javascript - 根据从自动完成数据中选择的数据将文本设置为 texfield
- r - 如何在 r 中编写复杂的副函数
- php - 为什么我的网站在 Google 登录后没有重定向
- javascript - 如何在 JavaScript 中访问跨类的属性
- php - php排序数组使用月份的键忽略其他键
- android-recyclerview - Recyclerview:无法获取项目计数值
- python - Python webdriver远程触发[WinError 10061]无连接
- python - 如何结合 tkinter 和海龟?
- python-2.7 - 如何在 django 模板的单个表体中添加两个 for 循环
- php - 使用 ajax php 和 mysql 增加数字