How to write struct back to h5 file
Show older comments
I am using a program called DeepLabCut to do markerless motion capture. After manually labelling data on still images, the program creates an h5 file (downloadable at this Google Drive link because Matlab Answers does not support uploading h5 files), part of which contains some metadata about the videos and the current project. I need to change that metadata in the h5 file, but am stuck on how to write that data back to the h5 file because it seems to be a struct.
I have also attached a csv file which is also generated as the human-readable version of this data, although the program only uses the h5 file.
First, I read in the h5 file and define the new metadata to be written.
% The full path to the h5 file
h5FilePath='/Volumes/GoogleDrive-117132924848468950297/My Drive/NJ GSS/DLC Home/NJ GSS Live-Group 8-2021-11-25/Folders Needing Renaming/standingBackOutsideShoes1/CollectedData_Group 8.h5';
% Read the h5 file and isolate the relevant metadata (don't need to modify
% the other field in the h5table struct).
h5table=h5read(h5FilePath,'/df_with_missing/table');
index=h5table.index;
% The first column of the csv (and the index field of h5table) contains a relative path. This is the prefix value that it
% should be changed to.
newPrefix='labeled-data/standingBackOutsideShoes1/';
Then, I modify that metadata.
% Change the value of index, where each column of the char array is one
% full path (prefix + img number)
clear newIndex;
for i=1:size(index,2)
if i<10
strNum=['00' num2str(i)];
elseif i<100
strNum=['0' num2str(i)];
else
strNum=num2str(i);
end
newIndex(:,i)=[newPrefix 'img' strNum '.png'];
end
h5table.index=newIndex;
Now, the h5table.index field has been appropriately modified. But I cannot write that same data back to the h5 file. The below code returns an error saying that type struct is not allowed, even though that is what was just read from the h5 file!
h5write(h5FilePath,'/df_with_missing/table',h5table);
Am I missing something? I'm sure this has something to do with type conversions between Matlab and h5, but I can't figure it out. How can I write back both fields of the h5table structure to that dataset in the h5 file? Thanks in advance.
Accepted Answer
More Answers (0)
Categories
Find more on Call Python from MATLAB 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!