Creating HDF5 file: How to create a GROUP inside a GROUP?

32 views (last 30 days)
Dear all
I'd like to create an HDF5 file ('file_ex.hdf') which should have the following structure:
>> h5disp('file_ex.hdf')
HDF5 file_ex.hdf
Group '/'
Attributes:
'Form': 'short'
Group '/ds1'
Group '/ds1/data1'
Dataset 'data'
Size: 1000x1200
Datatype: H5T_STD_U8LE (uint8)
Attributes:
'CLASS': 'Myclass'
'VERSION': 7.5
Group '/ds1/what'
Attributes:
'product': 'COMP'
'time': '000009'
Group '/what'
Attributes:
'Func': 'upper'
I managed to create an HDF5 file which contains the Attribute 'Form' and the Group '/ds1' -- but I did not manage to create a Group '/ds1/data1' contained in the Group '/ds1'. How can I create such a sub-group?
Here is the code I used:
>> h5create('file_ex.hdf','/ds1/data1',[10 20])
>> mydata = rand(10,20);
>> h5write('file_ex.hdf', '/ds1/data1', mydata)
>> h5writeatt('file_ex.hdf','/','Form','short');
The file generated by this code looks like this:
>> h5disp('file_ex.hdf')
HDF5 file_ex.hdf
Group '/'
Attributes:
'Form': 'short'
Group '/ds1'
Dataset 'data1'
Size: 10x20
MaxSize: 10x20
Datatype: H5T_IEEE_F64LE (double)
ChunkSize: []
Filters: none
FillValue: 0.000000

Accepted Answer

Jan Orwat
Jan Orwat on 6 Jul 2016
Edited: Jan Orwat on 6 Jul 2016
Use Low-Level Functions such as H5G.create to create custom/nested groups.
Example:
>> fid = H5F.create('myfile.h5');
>> plist = 'H5P_DEFAULT';
>> gid = H5G.create(fid,'my_group',plist,plist,plist);
>> gid2 = H5G.create(fid,'my_group2',plist,plist,plist);
>> gid1 = H5G.create(gid,'my_group_nested',plist,plist,plist);
>> H5G.close(gid1);
>> H5G.close(gid2);
>> H5G.close(gid);
>> H5F.close(fid);
>> h5disp('myfile.h5')
HDF5 myfile.h5
Group '/'
Group '/my_group'
Group '/my_group/my_group_nested'
Group '/my_group2'

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!