Writing non complete rows and columns to an hdf5 file

1 次查看(过去 30 天)
I have an array of data foo, let's say size(foo) = [1 175]
I also have a h5 file, let's call it bar.h5 with a dataset'/baz' of size [100 100]
Now I wan't to write foo to bar such that it fills the first 1.75 rows of bar such that the first row are completly filled and the second row has the first 75 values converted to the last 75 values of foo
After this I'll change foo and write the next 175 values to bar
I've tried doing
h5write('bar.h5','/baz',foo,[1 1], [2 75])
But this does not work. I don't know how to reshape foo in a way that would allow me to write this.
I realize that I could just make bar.h5/baz have size [10000 1] but then I'd need to reshape the data every time I wan't to look at it.

回答(1 个)

Ronit
Ronit 2024-8-27
Hello,
To reshape foo into a 2D array that matches the dimensions you want to write into the dataset /baz in the bar.h5 file, you can reshape it into a 2x100 array, where the first row is filled with the first 100 elements of foo, and the second row is partially filled with the remaining 75 elements, leaving the rest of the entries as zeros.
% Reshape foo into a 2x100 matrix
reshaped_foo = zeros(2, 100); % Initialize a 2x100 matrix with zeros
reshaped_foo(1, :) = foo(1:100); % Fill the first row with the first 100 elements
reshaped_foo(2, 1:75) = foo(101:175); % Fill the first 75 elements of the second row
% Write reshaped_foo to the dataset '/baz' in 'bar.h5'
h5write('bar.h5', '/baz', reshaped_foo, [1 1], size(reshaped_foo));
I hope it helps with your query!

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by