Read .mat files in Python

后端 未结 8 1597
时光说笑
时光说笑 2020-11-22 09:23

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

相关标签:
8条回答
  • 2020-11-22 09:45
    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.

    0 讨论(0)
  • 2020-11-22 09:48

    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')
    
    0 讨论(0)
提交回复
热议问题