Create HDF5 file from multidimensional data
16 views (last 30 days)
Show older comments
Let's assume I have a specific type of multidimensional data that is of shape 256*256*50. I have 7000 samples of this multideimensional data. How can I create an HDF5 file in MATLAB from this dataset? Since my dataset (256*256*50*7000) exceeds the available system memory I think my only option is to write the HDF5 data inside a for loop. Here is a sample code that returns an error "The amount of data to be written does not match the size of the HDF5 dataset.":
clear; close all; clc;
h5create('myfile.h5','/myDataset',[256 256 50 7000],'Datatype','single')
h5disp('myfile.h5')
I = imread('cameraman.tif');
for i=1:50
mydata(:,:,i) = I;
end
for i=1:7000
h5write('myfile.h5', '/myDataset', mydata)
end
2 Comments
Radek Chrapkiewicz
on 14 Jun 2020
You have to specify additionally count and stride within h5write.
For example:
h5create('test.h5','/1',[10,10,Inf],'ChunkSize',[10,10,1])
h5write('test.h5','/1',rand(10))
Yields the following error:
Error using h5write (line 115)
The amount of data to be written does not match the size of the HDF5 dataset.
But if you specify additionally start and count, you can make it:
h5write('test.h5','/1',rand(10),[1,1,1],[10,10,1])
h5write('test.h5','/1',rand(10),[1,1,2],[10,10,1])
h5write('test.h5','/1',rand(10),[1,1,3],[10,10,1])
data=h5read('test.h5','/1');
size(data)
Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!