Ask an expert. Trust the answer.

Your academic and career questions answered by verified experts

How to transfer variables from Matlab to Python

Date: 2022-12-19 12:30:17

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

Thanks in advance! 

Answers: 

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. 

 


Why Matlabhelpers ?

Our Matlab assignment helpers for online MATLAB assignment help service take utmost care of your assignments by keeping the codes simple yet of high-quality. We offer the most reliable MATLAB solutions to students pursuing their Computer Science course from the Monash University, the University of Sydney, the University of New South Wales, the University of Melbourne; to name a few. Approach us today for best Matlab solutions online!

whatsApp order on matlabhelpers.com

telegram order on matlabsolutions.com