Matlab 错误 - fplot();
>> fplot(fh,[-2 4])
??? Undefined function or variable "e".
Error in ==> myfun at 3
Y(:,2) = e(:).^x;
Error in ==> fplot at 102
x = xmin; y = feval(fun,x,args{4:end});
我尝试使用此 m 文件绘制两个函数。
function Y = myfun(x)
Y(:,1) = 3*x;
Y(:,2) = e(:).^x;
>> fplot(fh,[-2 4])
??? Undefined function or variable "e".
Error in ==> myfun at 3
Y(:,2) = e(:).^x;
Error in ==> fplot at 102
x = xmin; y = feval(fun,x,args{4:end});
I tried to plot two function using this m file.
function Y = myfun(x)
Y(:,1) = 3*x;
Y(:,2) = e(:).^x;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 Donnie 在他们的评论中提到的,变量
e
在您的 m 文件中未定义。如果您在其他地方定义了
e
,则必须将其传递给myfun
,以便函数知道它的值。由于 fplot 不接受具有多个输入值的绘图函数,因此您需要向其传递一个匿名函数。首先,您需要更改
myfun
的定义以包含e
作为输入:然后,您像这样创建函数句柄 fh (fh 仍然只接受一个输入,Matlab 使用
e
的值,因为它是在创建函数句柄时在工作区中定义的):最后,您可以像以前一样调用 fplot
As Donnie mentioned in their comment, the variable
e
is undefined in your m-file.If you have defined
e
elsewhere, you have to pass it tomyfun
so that the function knows its value. Sincefplot
does not accept plotting functions with more than one input value, you need to pass it an anonymous function.First, you need to change the definition of
myfun
to includee
as input:Then, you create your function handle fh like this (fh still only takes one input, Matlab uses the value of
e
as it was defined in the workspace at the time you create the function handle):Finally, you can call fplot like you used to