Matlab-具有多个输入的错误 [英] Matlab - bug with multiple inputs
本文介绍了Matlab-具有多个输入的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的功能:
function [o1 o2] = f(t, y)
o1 = y(2);
o2 = -sin(y(1));
end
当我从命令提示符处调用它时:
When I call it from command prompt:
f(1, [2,3])
ans = 3
为什么我只看到o1
?
而且,这不起作用
why do I only see o1
?
Also, this doesn't work
feval(f, 1, [2 3])
错误消息是
Input argument "y" is undefined.
Error in ==> f at 2
o1 = y(2);
请帮助,我不知道发生了什么事.
Please help, I have no idea what's going on.
推荐答案
feval应该已使用函数句柄或字符串调用,因此请使用
feval should have been called with a function handle or string, so use
feval(@f, 1, [2,3])
或
feval('f', 1, [2,3])
您将看到,这也仅返回该函数的第一个输出.要接收更多输出,您必须分配它们,例如
As you will see this also returns just the first output of the function. To receive further outputs you must assign them, e.g.
[o1, o2] = feval(@f, 1, [2, 3])
这篇关于Matlab-具有多个输入的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文