Is it possible to read binary MATLAB .mat files in Python?
I\'ve seen that SciPy has alleged support for reading .mat files, but I\'m unsuccessful with it. I install
from os.path import dirname, join as pjoin
import scipy.io as sio
data_dir = pjoin(dirname(sio.__file__), 'matlab', 'tests', 'data')
mat_fname = pjoin(data_dir, 'testdouble_7.4_GLNX86.mat')
mat_contents = sio.loadmat(mat_fname)
You can use above code to read the default saved .mat file in Python.
First save the .mat file as:
save('test.mat', '-v7')
After that, in Python, use the usual loadmat
function:
import scipy.io as sio
test = sio.loadmat('test.mat')