[英]How to call “__call__()” method of python class from matlab
我正在上这样的课:
class Select(object):
def __init__(self, interface):
...
def project(self, ID):
...
def __call__(self, datatype_or_path):
...
当我尝试从Matlab调用此方法(基本上是函子)时,如下所示:
select = Select(blah);
select('blah');
我收到以下错误:
Array formation and parentheses-style indexing with objects of class
'py.pyxnat.core.select.Select' is not allowed. Use objects of class
'py.pyxnat.core.select.Select' only as scalars or use a cell array.
编辑:
select.('__call__')('blah')
似乎也不起作用
来自Matlab技术支持:
我的名字叫sai,我正在写您的技术支持案例#01708094,内容涉及“通过matlab调用python函子”。
我了解您在从MATLAB调用python中定义的函子时遇到问题。
我看到您正在使用MATLAB R2014b。 请注意, 这是MATLAB R2014b中的一个已知问题,已在MATLAB R2015a中修复,并且在R2014b中没有已知的解决方法 。 如果可行,我建议您升级到MATLAB R2015a,这将帮助您解决此问题。
显然,您在代码中使用的Select
类是py.pyxnat.core.select.Select
,而不是您自己的Select
类。 检查您的导入(特别是在您导入自己的Select
类的行之后,检查“星号导入”- from xxx import *
-)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.