python无法从八度函数中解开返回的值
我在八度中具有称为dofft.m的函数,定义为:
function [Rx1,Rx2,fbins]=doFFT(file)
此函数按预期返回3行向量运行。
在Python中,我已经进口了Oct2py,
from oct2py import octave
我通过以下方式称呼此八度函数:
RX1,RX2,fbins=octave.doFFT(file)
我遇到一个错误,上面写着“ ValueError:不足以解开包装(预期3,获得1)”
作为测试,我重新定义了八度的功能以返回1个值,而是在python中称其为:
RX1=octave.doFFT(file)
这很好。
因此,问题似乎是让Python了解八度的回报格式。 我尝试将功能称为例如
[RX1, RX2, fbins]=octave.doFFT(file)
(RX1, RX2, fbins)=octave.doFFT(file)
,但仍然会遇到相同的错误。
如何格式化函数调用或八度的输出,以便python“理解”有3个项目正在返回?
I have a function called doFFT.m in Octave, defined as:
function [Rx1,Rx2,fbins]=doFFT(file)
this function runs as expected returning 3 row vectors.
In Python, I have oct2py imported,
from oct2py import octave
and I call this Octave function via:
RX1,RX2,fbins=octave.doFFT(file)
I get an error that says "ValueError: not enough values to unpack (expected 3, got 1)"
As a test I redefined the function in Octave to only return 1 value, and instead called it in Python as :
RX1=octave.doFFT(file)
and this worked fine.
So, the issue seems to be with having Python understand the return format from Octave.
I've tried calling the function as
[RX1, RX2, fbins]=octave.doFFT(file)
(RX1, RX2, fbins)=octave.doFFT(file)
for example, but still get either the same error.
How do I format the function call or the output from Octave, so that Python "understands" that there are 3 items being returned?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
oct2py
python桥要求在功能调用中明确表示返回值的预期数,例如。指定该函数返回3个值(在这种情况下为Numpy数组)。
当函数不返回任何内容时,必须称呼它表示它返回0个参数,即:
谢谢@tasos papastlyianou在他的评论中链接了Oct2py的文档。
the
oct2py
python bridge requires that the expected number of returned values to be explicitly expressed in the function call, for eg.specifies that the function returns 3 values (or numpy arrays in this case).
When a function doesn't return anything, it must be called indicating that it returns 0 arguments, ie:
Thank you to @Tasos Papastlyianou for linking the oct2py's documentation in his comment.