Reading multiple datasets in hdf5
22 views (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
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:
0 Comments
See Also
Categories
Find more on HDF5 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!