【问题标题】:how to access fields of .mat file opened with h5py如何访问使用 h5py 打开的 .mat 文件的字段
【发布时间】:2017-12-25 05:50:21
【问题描述】:

我有一个结构 S 存储在我用 MATLAB -v7.3 构建的 .mat 文件中(因为结构太大,>2GB 需要 -v7.3)。不幸的是,现在我无法用spio.loadmat('myfile.mat') 打开我的文件,所以我用h5py 打开它:

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

我的结构 S 有 3 个字段,大小为 700。

例如。

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

我的问题是,如何以 h5py 格式访问这些字段和一些数组值?使用f?

【问题讨论】:

标签: arrays matlab h5py


【解决方案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

【讨论】:

    猜你喜欢
    • 2018-02-13
    • 2017-10-05
    • 2020-04-26
    • 2016-09-15
    • 2021-02-23
    • 2014-12-24
    • 2011-12-02
    • 1970-01-01
    • 2013-10-19
    相关资源
    最近更新 更多