1

I have created following .mat file in MATLAB with '-v7.3' flag. I need this flag due to huge data-size. I used following command in MATLAB to save this file.

   save('sample10_properties.mat', 'stats','-v7.3')

Here is the link of the data

https://drive.google.com/file/d/195fj6Tl1n_drS8R_A6bdbOEc3rGkiMqS/view?usp=sharing

I can see stats variable in python but I don't know how to access. Any help will be appreciated.

import numpy as np 
import h5py 
f = h5py.File('sample10_properties.mat')
f.keys()   [u'#refs#', u'#subsystem#', u'stats']
f.values()  [<HDF5 group "/#refs#" (13951 members)>, <HDF5 group "/#subsystem#" (1   members)>, <HDF5 dataset "stats": shape (1, 6), type "<u4">]

The size of stats variable is (1390, 18). Thanks

ankit agrawal
  • 301
  • 1
  • 14
  • Unsnarling Matlab files stored in HDF5 format can be tricky for new users. Matlab creates "pointer objects" which aren't data, but instead give the path to another object in the file. Use **HDFView** to look at the schema. Table `MCOS` in Group `/#subsystem#` has a single row with 11 fields, each pointing to another object (e.g. `/#refs#/b`) The referenced table has 1x288 of 8-bit unsigned integers Then there are additional tables in `/#refs#/` for b0, b0b, b0c, b1, b1b, b1c. Not sure what to make of it. You see this with the SVHN datasets. – kcw78 May 07 '19 at 22:06
  • Link to my answer: [different-ways-of-accessing-the-hdf5-group-in-svhn](https://stackoverflow.com/questions/55566865/what-is-the-difference-between-the-two-ways-of-accessing-the-hdf5-group-in-svhn/55643382#55643382) about a similar Matlab/HDF5 file question. – kcw78 May 07 '19 at 22:08

1 Answers1

1

If you want to load a single value

import h5py
f = h5py.File('sample10_properties.mat','r')
myvar = f['myvar'].value

All the values

import numpy as np
import h5py

f = h5py.File('simdata_020_01.mat','r')
variables = f.items()

for var in variables:
    name = var[0]
    data = var[1]
    print "Name ", name  # Name
    if type(data) is h5py.Dataset:
        # If DataSet pull the associated Data
        # If not a dataset, you may need to access the element sub-items
        value = data.value
        print "Value", value  # NumPy Array / Value

I'm in a time crunch so I wrote this real quick, apologies for any errors or not fitting your data.

Julia Fasick
  • 121
  • 7