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.
0 件のコメント
回答 (1 件)
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!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で HDF5 についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!