Question

Is there any way to create .mat v7.3 files from Python? I have been managed to create hdf5 files from Python but not in converting them into .mat v7.3 files. I found a package called hdf5storage but I don't know how to use it.

Was it helpful?

Solution

Example (requires Python >= 2.6 with the NumPy and h5py >= 2.1 packages):

import hdf5storage # get code on https://pypi.python.org/pypi/hdf5storage/0.1.3

matcontent = {}
matcontent[u'some_numbers'] = [10, 50, 20] # each key must be a unicode string
hdf5storage.write(matcontent, '.', 'test.mat', store_python_metadata=False, matlab_compatible=True)

In Matlab:

enter image description here


If you want to have a matrix instead of a cell array in Matlab:

import hdf5storage # get code on https://pypi.python.org/pypi/hdf5storage/0.1.3
import numpy as np

matcontent = {}
matcontent[u'some_numbers'] = np.array([10, 50, 20]) # each key must be a unicode string
hdf5storage.write(matcontent, '.', 'test2.mat', matlab_compatible=True)

enter image description here

As you will notice, the second example is much faster (>x10).


More generally, refer to the documentation for the data storage matching:

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top