Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call MATLAB Functions from Python

Status
Not open for further replies.

PhilippB

Student
May 10, 2021
3
Hello everyone,

I am currently working on a project in which I am doing a data analysis with Python. The data that I use as a basis comes from a Matlab script that was not written by me. My approach for the connection is based on the link below.


But when I try to run import matlab.engine in my Jupyter notebook, it shows the following error message:

ModuleNotFoundError: No module named 'matlab.engine'; 'matlab' is not a package​

That surprises me because I have actually already installed the Matlab package several times. I use Python 3.7 and my Matlab version is 2021a (with license).

I hope that someone can help me. I am also grateful for alternative approaches.

Best regards Philipp
 
Replies continue below

Recommended for you

MatLab may be installed, but is there actually a module named 'matlab.engine'? I'm guessing not, hence the error you're seeing.

Dan - Owner
Footwell%20Animation%20Tiny.gif
 
As for an alternate approach: I'd export the data from matlab into a file (csv for instance) and then read that into python..

Are the data from the matlab script just a static set or are you trying to analyze them continuously as they are produced?
 
I'd suggest starting off by reading the matlab help for

matlab.engine.start_matlab
Start MATLAB Engine for Python
Syntax
eng = matlab.engine.start_matlab()example
eng = matlab.engine.start_matlab(option)

I'm not quite sure why this step is so remarkable.

Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376
 
Thank you everyone for helping me.

@MacGyverS2000:
I followed the instructions in the following link. I therefore believe that engine should actually be part of the Matlab package (similar to matplotlib.pyplot where matplotlib only has to be installed). I am not sure though. Do you have any ideas how to install it otherwise?

@onatirec:
Indeed, it would work that way. Since the analysis should ultimately be integrated into a running system, it would certainly be possible, but in the end it would be more of a work-around. I therefore see this as a last resort.

@GregLocock:
Unfortunately, the problem lies earlier. I cannot call an expression with matlab.engine without getting an error message. So I believe the problem is with the installation. I just have no idea where.

Thanks alot.
Philipp
 
I found a solution by accident. For some reason, import matlab.engine from my Jupyter Notebook is not running. But if I call it in PyCharm (same environment) it works.

Just one last question. Could that be the reason or am I missing something?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor