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!