问题描述
我正在使用Oct2Py,以便在我的Python代码中使用一些M文件.假设我有一个简单的Matlab函数:
I'm using Oct2Py in order to use some M-files in my Python code. Let's say that I have this simple Matlab function :
function [a, b] = toto(c);
a = c;
b = c + 1;
end
如果我在Octave中调用它,显然会发生:
What happens if I call it in Octave is obviously :
>> [x,y] = toto(3)
x = 3
y = 4
现在,如果我使用oct2py在Python中调用它:
Now if I call it in Python, using oct2py :
from oct2py import octave
my_dir = "D:\\My_Dir"
octave.addpath(my_dir)
a,b = octave.toto(3)
这将返回:
似乎octave.toto(n)仅返回第一个值,当我期望两个值时...有人可以向我解释我应该做什么吗?谢谢
It seems like octave.toto(n) only returns the first value, when I'd expect two... Can anyone explain to me what I should be doing ? Thanks
推荐答案
在旧版本的Oct2Py(3.x及更早版本)中,输出参数的数量是通过Python中的调用推断出来的,因此,如果您需要多个输出,您只需请求两个输出
In older versions of Oct2Py (3.x and older), the number of output arguments was inferred from the call within Python, so if you wanted multiple outputs, you would simply request both outputs
a, b = octave.toto(3)
但是,从4.0版开始 a>现在,您需要在函数调用中使用nout
kwarg来显式指定所需数量的输出参数
However, as of version 4.0 you now need to use the nout
kwarg to your function call to explicitly specify the desired number of output arguments
a, b = octave.toto(3, nout=2)
从4.0发行说明中
这篇关于Oct2Py仅返回第一个输出参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!