According to a StackOverflow post, one can use **scipy** to read a matlab file, but it does not support the latest format *Version 7.3 and later*. Instead, one can use **h5py** since the format *Version 7.3 and later* follows **HDF5**.

Then, I looked for a solution to read a matlab file by using **h5py** and found another StackOverflow post, which describes how to extract the names of variables and their values. Since I know that **Panda**‘s DataFrame is good to deal with labelled datasets, I dug **Pandas** documents. What is possible is to convert a dict to **Pandas** Series. I think it is because the array for each label can be multi-dimensional.

import numpy as np import pandas as pd import h5py f = h5py.File('FileName','r') dataset = dict() for name, data in f.items(): if type(data) is h5py.Dataset: dataset[name] = data.value series = pd.Series(dataset)

So one can address the content of a variable `x`

by `series['x']`

.

Advertisements

Pingback: Reading HDF5 in MATLAB – Jae-Seung's Weblog