Reading MATLAB v7.3 .mat files in Python in Ubuntu
While the scipy io package will allow you to load older MATLAB .mat data files in Python, starting in v7.3 the default data format has switched to the sturdier HDF5 storage format. This means you'll need to install an HDF5 reader to load these files in Python. While the python-h5py package is available in the repositories, it hasn't been updated in quite a while, so here are the steps I'd recommend:
- Install the libhdf5 package with apt-get:
sudo apt-get install libhdf5-serial-dev
- Use easy_install to install the latest h5py library:
sudo easy_install h5py
- Import and load new .mat files like any other hdf5 file:
import h5py f = h5py.File('x.mat') x=f["x"] print xHDF5 dataset "x": shape (3, 3), type "f8"