How to change the type when creating HDF5 attributes.

8 ビュー (過去 30 日間)
Kang Peng
Kang Peng 2022 年 4 月 1 日
コメント済み: Les Beckham 2022 年 4 月 1 日
Hi all,
I want to create attributes for a HDF5 file like this which is read from HDFView:
and here is my Matlab code:
h5writeatt('tt.h5','/tide','Dimension', "XY");
h5writeatt('tt.h5','/tide','Discretization', [2.0 3.0]);
h5writeatt('tt.h5','/tide','Origin', [-1.0 -1.0]);
h5writeatt('tt.h5','/tide','Max Buffer Size', int32(4));
h5writeatt('tt.h5','/tide','Cell Centered', "TRUE");
h5writeatt('tt.h5','/tide','Time Units', "d");
then I read it in HDFView, and the result is:
How shoud I change the type when creating the attributes? And the type of "Transient" is like BOOL, how shoud I set this type?
Thanks,
Peter
  2 件のコメント
Les Beckham
Les Beckham 2022 年 4 月 1 日
編集済み: Les Beckham 2022 年 4 月 1 日
If I read your question correctly you are primarily concerned with the type of the "Transient" attribute, but you didn't show the code you used to write that attribute. What was the type of the data you wrote to that attribute? Was it logical or a string or a number?
Kang Peng
Kang Peng 2022 年 4 月 1 日
The code in the question is already all the code for attribute writing, and I put out the whole code for creating the HDF5 file.
D = zeros(26,3,636);
for i = 1:26
a = i*3-2;
E = Pressure([a:a+2],:);
D(i,:,:) = E;
end
h5create('tt.h5', '/tide/Data', [26 3 636]);
h5write('tt.h5','/tide/Data',D);
h5create('tt.h5', '/tide/Time', 26);
h5write('tt.h5','/tide/Time',Time);
h5writeatt('tt.h5','/tide','Dimension', "XY");
h5writeatt('tt.h5','/tide','Discretization', [2.0 3.0]);
h5writeatt('tt.h5','/tide','Origin', [-1.0 -1.0]);
h5writeatt('tt.h5','/tide','Max Buffer Size', int32(4));
h5writeatt('tt.h5','/tide','Transient', "TRUE");
h5writeatt('tt.h5','/tide','Time Units', "d");
But I don't know how to modify the type of the attribute. The first picture is the type of each attribute I want to set, how can I write the type of the attribute?

サインインしてコメントする。

回答 (1 件)

Les Beckham
Les Beckham 2022 年 4 月 1 日
編集済み: Les Beckham 2022 年 4 月 1 日
I don't have any hd5 files to test this with, but I suspect that if you change this
h5writeatt('tt.h5','/tide','Transient', "TRUE");
to this
h5writeatt('tt.h5','/tide','Transient', true);
you may achieve what you want.
"TRUE" is not a boolean (logical) value, it is a string.
  4 件のコメント
Kang Peng
Kang Peng 2022 年 4 月 1 日
That's right the type is also not ENUM if I use 1/0 isntead of true/false.
Thanks for answering my question.
Les Beckham
Les Beckham 2022 年 4 月 1 日
You are welcome. Sorry it didn't help.
Good luck.
If your Matlab is under maintenance, you might want to contact Mathworks support to see if they can help. There is a "Contact Support" link at the bottom of this page.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeHDF5 についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by