【问题标题】:Type-Error while using mlabwrap-purepy to call custom functions使用 mlabwrap-purepy 调用自定义函数时出现类型错误
【发布时间】:2014-04-28 10:52:06
【问题描述】:

我从 https://github.com/cpbotha/mlabwrap-purepy 下载了 mlabwrap-purepy 接下来,我使用以下命令调用 matlab 函数:

%% Python init <br>
import matlabwrap <br>
mlab = matlabwrap.init() <br>
%% <br>

我可以轻松调用所有内置的 matlab 函数,但是在调用自定义函数时我遇到了类型错误。考虑以下 matlab 函数:

%% Matlab Function %% <br>
function [x] = get_x() <br>
  x = 1; <br>
end <br>
%%% <br>

当我运行时,mlab.get_x() 我收到以下错误:

TypeError: cannot concatenate 'str' and 'numpy.ndarray' objects <br>

对可能发生的事情有任何线索吗?
我看了看:Run a MATLAB script from python + pass args - 但它并没有解决我的问题。

但是,当我使用没有输入参数的 mlab.eval 运行简单的 matlab 脚本时,它可以工作,例如:

x = mlab.eval('get_x') <br>

我希望能够像 mlab.function_name(arg1,arg2) 一样运行,但我遇到了上述错误。有什么线索可以解决这个问题吗?

【问题讨论】:

    标签: matlab python-2.7 typeerror mlabwrap


    【解决方案1】:

    尝试向函数 get_x() 添加一些帮助字符串。

    即在 get_x.m 文件中:

    function [x] = get_x()
    % GET_X return x
    x = 1;
    end
    

    【讨论】:

      猜你喜欢
      • 2011-06-16
      • 1970-01-01
      • 2016-11-01
      • 2021-10-25
      • 2013-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多