Calling Matlab function in python3.6 is ten times slower than runing the same function directly in Matlab

Viewed 250

My classmate and I are working on a program and I need to call the m. file he wrote to solve a equation.

However, I found out It is ten times slower to call Matlab functions in python than runing the same function directly in Matlab. Can I solve this problem?

The function in python is described as below:

engine = matlab.engine.start_matlab()
print('start_engine')
t_begin = time.time()
rod, s1, s2, s3 = engine.shape_sensing(1.96, 2.77, 1.45, nargout=4)
t_end = time.time()
t = t_end-t_begin
print(t)
1 Answers

That's just the overhead for calling MATLAb from python and not doing it directly.

Maybe you could improve performance by using parquet, that's a format to exchange code between Python and Matlab. If you have large column-oriented data that makes the transfer more efficient. Check it out here: https://www.mathworks.com/help/matlab/parquet-files.html

You can also find information about this here: https://blogs.mathworks.com/racing-lounge/2020/09/14/using-matlab-and-python-together/ It's about using Python from MATLAB but the conversion format is the same

Related