×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Call MATLAB Functions from Python

Call MATLAB Functions from Python

Call MATLAB Functions from Python

(OP)
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.

https://de.mathworks.com/help/matlab/matlab_extern...

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

RE: Call MATLAB Functions from Python

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
http://www.Hi-TecDesigns.com

RE: Call MATLAB Functions from Python

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?

RE: Call MATLAB Functions from Python

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: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?

RE: Call MATLAB Functions from Python

(OP)
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?
https://de.mathworks.com/help/matlab/matlab_extern...

@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

RE: Call MATLAB Functions from Python

(OP)
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?

RE: Call MATLAB Functions from Python

I think you need to add your path to Jupyter specifically, it is different to your normal pythonpath from memory.

You can add the path to the install of matlab.engine temporarily at the start of your script. Check here for details.

https://engineervsheep.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close