Error writing array of class double to a HDF5 file

33 ビュー (過去 30 日間)
Enda Carroll
Enda Carroll 2019 年 5 月 23 日
回答済み: Shivam Sardana 2019 年 5 月 30 日
Hi
I am having trouble with the following code:
data = zeros(100);
for i = 1:100
for j = 1:100
data(i, j) = rand(1,1) + 1i*rand(1,1);
end
end
h5create("test.h5", "/test", size(data));
h5write("test.h5", "/test", data);
I am trying to write data of class double to a hdf5 file which I create but I recieve the following error
Warning: Conversion from double to datatype H5T_NATIVE_DOUBLE may clamp some values.
> In H5D.write (line 100)
In h5write (line 138)
Error using hdf5lib2
The class of input data must be double instead of double when the HDF5 class is H5T_IEEE_F64LE.
Error in H5D.write (line 100)
H5ML.hdf5lib2('H5Dwrite', varargin{:});
Error in h5write (line 138)
H5D.write(dataset_id,'H5ML_DEFAULT',memspace_id,filespace_id,dxpl,Data);
I have tried specifying the datatype when I create the hdf5 file but I recieve the same error message
h5create("test.h5", "/test", size(data), 'Datatype','double');
h5write("test.h5", "/test", data);
Thanks in advance

採用された回答

Shivam Sardana
Shivam Sardana 2019 年 5 月 30 日
Problem with your code is variable data is of complex double type. The error indicates there is a mismatch. To resolve this convert data from complex double type to double type.
data = zeros(100);
for i = 1:100
for j = 1:100
data(i, j) = rand(1,1) + 1i*rand(1,1);
end
end
data = real(data);
h5create("test.h5", "/test", size(data), 'Datatype','double');
h5write("test.h5", "/test", data);

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by