Input arguments for MATLAB Engine function

自闭症网瘾萝莉.ら 提交于 2020-07-04 00:23:03

问题


I'm trying to use MATLAB engine to call a MATLAB function in Python, but I'm having some problems. After manage to deal with NumPy arrays as input in the function, now I have some error from MATLAB:

MatlabExecutionError: Undefined function 'simple_test' for input arguments of type 'int64'.

My Python code is:

import numpy  as np
import matlab
import matlab.engine
eng =  matlab.engine.start_matlab()

eng.cd()

Nn = 30
x= 250*np.ones((1,Nn)) 
y= 100*np.ones((1,Nn)) 
z = 32
xx = matlab.double(x.tolist())
yy = matlab.double(y.tolist())
Output = eng.simple_test(xx,yy,z,nargout=4)
A = np.array(Output[0]).astype(float)
B = np.array(Output[1]).astype(float)
C = np.array(Output[2]).astype(float)
D = np.array(Output[3]).astype(float)

and the Matlab function is:

function [A,B,C,D] = simple_test(x,y,z)

A = 3*x+2*y;
B = x*ones(length(x),length(x));
C = ones(z);
D = x*y';
end

Is a very simple example but I'm not able to run it! I know the problem is in the z variable, because when I define z=32 the error is the one I mentioned, and when I change for z=32. the error changes to

MatlabExecutionError: Undefined function 'simple_test' for input arguments of type 'double'.

but I don't know how to define z.

来源:https://stackoverflow.com/questions/62399896/input-arguments-for-matlab-engine-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!