h5create creates Extendable (unlimited) dataset also if Size == 0

조회 수: 9 (최근 30일)
Ernst van der Pols
Ernst van der Pols 2025년 6월 4일
댓글: Ernst van der Pols 2025년 6월 18일
According to the h5create() documentation, you can create a dataset with unlimited dimension(s) by specifying Inf for any of the Size dimensions.
However, when creating (for a test case) an empty dataset with Size == 0, I found that that is also an indication for an Extendable dataset. I got the error message that I had forgotten to specify the ChunkSize, as required for extendable datasets. This undocumented feature can be read on line 177 of h5create.m:
% Setup Extendable.
options.Extendable = false(1,numel(options.Size));
options.Extendable(isinf(options.Size)) = true;
options.Extendable(options.Size == 0) = true; % <- line 177
It is not strange to handle the Size == 0 case as indicator that (more) data will follow later (thus requiring extendability and a ChunkSize). If that is the intended behaviour, please update the documentation likewise.
An alternative approach could be that if Size == 0 the presence of ChunkSize determines if the dataset will be extendable. That will require an update of h5create as well, and might break existing code, relying on the current exception behaviour.
  댓글 수: 1
Abhipsa
Abhipsa 2025년 6월 6일
I have also observed this behavior when using h5create with Size == 0, MATLAB throws an error unless ChunkSize is explicitly specified.

댓글을 달려면 로그인하십시오.

채택된 답변

Deepak
Deepak 2025년 6월 16일
I understand that you are trying to create an initially empty HDF5 dataset using "h5create" in MATLAB by specifying (Size == 0), and observed that this triggers an error unless "ChunkSize" is provided. This behavior is indeed due to MATLAB internally treating any zero-sized dimension as extendable, similar to using "Inf", though this is not currently documented. As a result, specifying (Size = 0) requires a valid "ChunkSize", just like for extendable datasets.
While using a literal 0 in the "Size" argument may appear intuitive, the recommended and supported way to create an empty, extendable dataset is by using "Inf" in the corresponding dimension. For example,
h5create(filename, '/data', [Inf 10], 'ChunkSize', [10 10])
creates a dataset with an initial size of [0 10], allowing future expansion along the first dimension. This approach ensures compatibility and avoids ambiguity in "h5create" behavior.
Please find attached the documentation of "h5create" as reference:
I hope this helps.
  댓글 수: 1
Ernst van der Pols
Ernst van der Pols 2025년 6월 18일
Thanks for confirming my observation. At least this topic now functions as addendum to the documentation.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Preprocessing에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by