|
@@ -0,0 +1,38 @@
|
|
|
+function [data, all_strings] = get_all_data_from_level_h5_rec(filename, str, data, all_strings)
|
|
|
+% This function recursively reads data from an HDF5 file.
|
|
|
+%
|
|
|
+% INPUT:
|
|
|
+% filename: A string that identifies the HDF5 file from which to extract data.
|
|
|
+% str: The group from which to start extracting data.
|
|
|
+% data: A cell array to add and store the extracted data.
|
|
|
+% all_strings: A cell array to add and store the paths of the extracted
|
|
|
+% datasets (for control)
|
|
|
+%
|
|
|
+% OUTPUT:
|
|
|
+% data: A cell array containing the extracted data for each dataset.
|
|
|
+% all_strings: A cell array containing the paths of the extracted datasets.
|
|
|
+
|
|
|
+% authors: Francesco E. Vaccari
|
|
|
+% date: 03/2024
|
|
|
+
|
|
|
+% Get information about the HDF5 file.
|
|
|
+info = h5info(filename, str);
|
|
|
+
|
|
|
+% If there are groups in the current group...
|
|
|
+if ~isempty(info.Groups)
|
|
|
+ for i = 1:length(info.Groups)
|
|
|
+ % ...recursively call this function on the group (to dig in the
|
|
|
+ % hierarchy)
|
|
|
+ [data, all_strings] = get_all_data_from_level_h5_rec(filename, info.Groups(i).Name, data, all_strings);
|
|
|
+ end
|
|
|
+ % If there are no groups but there are datasets in the current group...
|
|
|
+elseif isempty(info.Groups) && ~isempty(info.Datasets)
|
|
|
+ row_num = size(data,1);
|
|
|
+ for i = 1:length(info.Datasets)
|
|
|
+ % ...read the data from the dataset and store it in the 'data' cell array.
|
|
|
+ data{row_num+1,i} = h5read(filename, [info.Name '/' info.Datasets(i).Name]);
|
|
|
+ all_strings{row_num+1,i} = [info.Name '/' info.Datasets(i).Name];
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+end
|