Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to transfer variables from Matlab to Python

I would like to transfer some of variables calculated in Matlab (R2022a) to Python environment (3.10).

I have figured out that the SciPy package has function loadmat() and I may save vars in mat file and then I should read the file with Python. However, I’m not able to use the function.

import scipy
scipy.loadmat('myVars.mat')

The interpreter argues that there is no such function as loadmat().

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks in advance!

>Solution :

You are almost at home. The function loadmat()' is in a sub-package scipy.io’. IO means input/output.
You should import and use it in that way:

import scipy.io
var_from_mat = scipy.io.loadmat('myVars.mat')

For the future, remember to check if the function is defined in the main package or in some of the sub-packages.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading