3

I am trying to load a large 400x300x60x28 dataset from Matlab (.mat file) into Python as an HDF file, but every time I try to see what's in the file it says it is empty.

Some things I've tried so far:

INPUT:

    f=h5py.File(r'D:\Natalie\Research\Vascular Hand\output.mat','r')
    print(f)

OUTPUT:

    <HDF5 file "output.mat" (mode r+)>

INPUT:

    store=pd.HDFStore(r'D:\Natalie\Research\Vascular Hand\output.mat')
    print(store)

OUTPUT:

    <class 'pandas.io.pytables.HDFStore'>
    File path: D:\Natalie\Research\Vascular Hand\output.mat
    Empty

INPUT:

    f = pd.read_hdf(r'D:\Natalie\Research\Vascular Hand\output.mat')

OUTPUT:

    ValueError: No dataset in HDF5 file.

It's saying there is no dataset, but I just opened the same file in Matlab and it has over 500,000 elements. Just to give some context, it is a variable of type 4-D single in Matlab and it is time-of-arrival data from blood circulation tracked through MRI scans.

Nat
  • 61
  • 3
  • Is the mat file saved as version 7.3? Does it work if you save it with [`h5write`](https://mathworks.com/help/matlab/ref/h5write.html)? – m7913d Jul 14 '17 at 15:33
  • Yes, it is version 7.3. I tried h5write like you said to save it as a .h5 file, but it still recognizes the dataset as empty when I try to read it into Python. – Nat Jul 15 '17 at 01:49

1 Answers1

0

To read .mat files one might use scipy.io.loadmat

data = scipy.io.loadmat("example.mat")
Gonçalo Peres
  • 11,752
  • 3
  • 54
  • 83