Problems with input arguments in function
2 次查看(过去 30 天)
显示 更早的评论
Hi, I'm trying to call matlab from python and I'm having some problems, it seems the variable z is not the type matlab wants??
I only know that probably the problem is in this variable because when I modify the type to double or int the error is always with the same type.
this is my python script:
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))
zz = matlab.double([[32]])
xx = matlab.double(x.tolist())
yy = matlab.double(y.tolist())
Output = eng.simple_test(xx,yy,zz,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 this is my matlab function:
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
and this is the error I'm getting:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/317430/image.png)
2 个评论
Andrey Smolyakov
2020-6-17
It seems more like MATLAB just couldn't find your function. Make sure that it is located in the directory which is added to the MATLAB path. And, probably, read this.
回答(1 个)
Abhishek Gupta
2020-9-9
Hi Jeniffer,
Yes, as @Andrey suggested, you need to make sure that your folder containing the ‘simple_test’ function is on the MATLAB search path.
To check the same, you can follow the below steps: -
- Open MATLAB
- Go to Home tab -> Environment section -> Click Set Path
- In the Set Path dialog box, browse through the MATLAB search path, and see if your folder exists in the list. If not, then click 'Add with Subfolders…’ and select your folder containing your MATLAB files.
- Or you can also make use of the ‘addpath()’ function.
Also, referring you to the following links, which might help you in resolving the issue: -
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call MATLAB from Python 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!