Reading multiple datasets in hdf5

22 views (last 30 days)
Amit Sinha
Amit Sinha on 24 May 2023
Answered: Animesh on 30 May 2023
I have an HDF5 file format where the datasets are in a group like /abc/xyz1 to /abc/xyznnn
All these have similar datasets: name, age, loc
How do I loop through these n subgroups to read all the data from the hdf5 file?

Answers (1)

Animesh
Animesh on 30 May 2023
Hello!
You can use MATLAB's h5info function to get information about the contents of the HDF5 file(including the names of the datasets and groups) and h5read to read the data from the dataset.
You can do something like this to read all the data from all subgroups of "/abc":
filename = 'yourfile.h5';
info = h5info(filename, '/abc');
subgroup_names = {info.Groups.Name};
for i = 1:length(subgroup_names)
groupname = subgroup_names{i};
name = h5read(filename, strcat(groupname, '/name'));
age = h5read(filename, strcat(groupname, '/age'));
loc = h5read(filename, strcat(groupname, '/loc'));
% Do something with the data
end
You may refer to the following documentation for more information:

Tags

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!