0

I have a structure S that I have stored in a .mat file I built with MATLAB -v7.3 (because the struct was too large, >2GB requires -v7.3). Unfortunately, now I cannot open my files with spio.loadmat('myfile.mat') so I am opening it with h5py:

f = h5py.File('myfile.mat')

My struct, S, has 3 fields and a size of 700.

Ex.

S(1).field1 = some array
S(1).field2 = some array
S(1).field3 = some array
....
S(700).field1 = some array
S(700).field2 = some array
S(700).field3 = some array

My question is, how do I access these fields and some array values in the h5py format? Using f?

haxtar
  • 1,962
  • 3
  • 20
  • 44
  • 1
    Start by exploring the nested `group` and `dataset` keys. https://stackoverflow.com/a/27699851/901925. Look on the sidebar for other links. – hpaulj Jul 19 '17 at 19:26

1 Answers1

1
idx = f['S/field1'][0][0]  #serves as an index where f contains the field object
field1_object = f[idx] #access the field object
field1_content = field1_object.value #reveal the array

...

idx = f['S/field2'][699][0]
field2_object = f[idx]
field2_content = field2_object.value
haxtar
  • 1,962
  • 3
  • 20
  • 44