Error writing array of class double to a HDF5 file

31 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Shivam Sardana
Shivam Sardana il 30 Mag 2019
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);

Più risposte (0)

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by