MATLAB读取hdf文件
https://blog.csdn.net/good_learner_1/article/details/100047950 版权
1. 显示hdf文件中的数据集以及属性等等信息
2. 读取hdf文件中的数据
3. 读取数据集的属性
4. 创建hdf文件
5. 往新建的hdf中写入数据
6. 给数据集写属性
官方中文文档
1. 显示hdf文件中的数据集以及属性等等信息
h5disp('文件名.hdf');
1
例如:
h5disp('dataset/sample_A_padded_20160501.hdf');
# 输出:
HDF5 sample_A_padded_20160501.hdf
Group'/'
Attributes:
'file_format': '0.2'
Group'/annotations'
Attributes:
'offset': 1520.000000 3644.000000 3644.000000
Dataset'ids'
Size:432
MaxSize:432
Datatype: H5T_STD_U64LE (uint64)
ChunkSize: []
Filters: none
FillValue:0
Dataset'locations'
Size:3x432
MaxSize:3x432
Datatype: H5T_IEEE_F32LE (single)
ChunkSize: []
Filters: none
FillValue:0.000000
Dataset'types'
Size:432
MaxSize:432
Datatype: H5T_STRING
StringLength: variable
Padding: H5T_STR_NULLTERM
CharacterSet: H5T_CSET_UTF8
Character Type: H5T_C_S1
ChunkSize:432
Filters: deflate(4)
Group'/annotations/comments'
Dataset'comments'
Size:17
MaxSize:17
Datatype: H5T_STRING
StringLength: variable
Padding: H5T_STR_NULLTERM
CharacterSet: H5T_CSET_UTF8
Character Type: H5T_C_S1
ChunkSize: []
Filters: none
Dataset'target_ids'
Size:17
MaxSize:17
Datatype: H5T_STD_U64LE (uint64)
ChunkSize: []
Filters: none
FillValue:0
Group'/annotations/presynaptic_site'
Dataset'partners'
Size:2x216
MaxSize:2x216
Datatype: H5T_STD_U64LE (uint64)
ChunkSize: []
Filters: none
FillValue:0
Group '/volumes'
Dataset 'raw'
Size:3072x3072x200
MaxSize:3072x3072x200
Datatype: H5T_STD_U8LE (uint8)
ChunkSize:192x96x7
Filters: deflate(4)
Attributes:
'resolution': 40.000000 4.000000 4.000000
Group'/volumes/labels'
Dataset'clefts'
Size:1250x1250x125
MaxSize:1250x1250x125
Datatype: H5T_STD_U64LE (uint64)
ChunkSize:79x79x4
Filters: deflate(4)
Attributes:
'resolution': 40.000000 4.000000 4.000000
'offset': 1520.000000 3644.000000 3644.000000
Dataset'neuron_ids'
Size:1250x1250x125
MaxSize:1250x1250x125
Datatype: H5T_STD_U64LE (uint64)
ChunkSize:79x79x4
Filters: deflate(4)
Attributes:
'resolution': 40.000000 4.000000 4.000000
'offset': 1520.000000 3644.000000 3644.000000
1
2. 读取hdf文件中的数据
data= h5read('文件名.hdf','数据集名');
1
例如:
raw = h5read('dataset/sample_A_padded_20160501.hdf',' /volumes/raw ');
1
3. 读取数据集的属性
attribute = h5readatt('文件名.hdf','数据集名','属性名');
1
例如:
resolution = h5readatt('dataset/sample_A_padded_20160501.hdf','/volumes/raw','resolution');
1
4. 创建hdf文件
h5create('文件名.hdf','数据集名', 数据大小,'Datatype','数据类型');
1
例如:
h5create('downs_dataset/downsample_A_padded_20160501.hdf','/volumes/raw', size_downs_raw,'Datatype','uint8');
1
5. 往新建的hdf中写入数据
h5write('文件名.hdf','数据集名', 数据变量);
1
例如:
h5write('downs_dataset/downsample_A_padded_20160501.hdf','/volumes/raw', downs_raw);
1
6. 给数据集写属性
h5writeatt('文件名.hdf','数据集名','属性名', 属性变量);
1
例如:
h5writeatt('downs_dataset/downsample_A_padded_20160501.hdf','/volumes/raw','resolution', resolution);
1