Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reading v 7.3 mat file in python

I am trying to read a matlab file with the following code

import scipy.io mat = scipy.io.loadmat('test.mat') 

and it gives me the following error

raise NotImplementedError('Please use HDF reader for matlab v7.3 files') NotImplementedError: Please use HDF reader for matlab v7.3 files 

so could anyone please had the same problem and could please any sample code

thanks

like image 565
Shan Avatar asked Jun 26 '13 09:06

Shan


People also ask

Can Python read a .MAT file?

Beginning at release 7.3 of Matlab, mat files are actually saved using the HDF5 format by default (except if you use the -vX flag at save time, see in Matlab). These files can be read in Python using, for instance, the PyTables or h5py package.

How do I read a .MAT file?

How to Open an MAT File. MAT files that are Microsoft Access Shortcut files can be created by dragging a table out of Access and to the desktop or into another folder. Microsoft Access needs to be installed in order to use them. MATLAB from MathWorks can open MAT files that are used by that program.


2 Answers

Try using h5py module

import h5py with h5py.File('test.mat', 'r') as f:     f.keys() 
like image 72
Shai Avatar answered Oct 06 '22 14:10

Shai


I've created a small library to load MATLAB 7.3 files:

pip install mat73 

To load a .mat 7.3 into Python as a dictionary:

import mat73 data_dict = mat73.loadmat('data.mat') 

simple as that!

like image 30
skjerns Avatar answered Oct 06 '22 13:10

skjerns