SciPy's io
module can read and write MATLAB files, allowing for easy integration with MATLAB data.
from scipy.io import savemat, loadmat import numpy as np # Creating a MATLAB file mat_dict = {'a': np.array([1, 2, 3]), 'b': np.array([4, 5, 6])} savemat('example.mat', mat_dict) # Loading a MATLAB file data = loadmat('example.mat') print("Loaded data:", data)
In this example, we save a dictionary of arrays to a MATLAB file and then load it back into Python.