Problems with input arguments in function

1 view (last 30 days)
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:
  2 Comments
Andrey Smolyakov
Andrey Smolyakov on 17 Jun 2020
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.
Jeniffer Viegas
Jeniffer Viegas on 17 Jun 2020
How do I know if it is in the Matlab path? I know that I put both scripts, the python and the matlab one in the same folder...

Sign in to comment.

Answers (1)

Abhishek Gupta
Abhishek Gupta on 9 Sep 2020
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: -
  1. Open MATLAB
  2. Go to Home tab -> Environment section -> Click Set Path
  3. 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.
  4. 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: -

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!