NeuroJSON / easyh5

EasyH5 Toolbox - An easy-to-use HDF5 data interface (loadh5 and saveh5) for MATLAB
BSD 3-Clause "New" or "Revised" License
13 stars 10 forks source link

customizable complex numbers storage (closes #4) #5

Closed matteosecli closed 4 years ago

matteosecli commented 4 years ago

As there is no standard way to store complex arrays in HDF5, this provides a new option for saveh5 and loadh5, to be used as saveh5(...,'ComplexFormat',{'myReal','myImag'}) (and similarly for loadh5.

Example:

myCxMat = randn(4,5)+1i*randn(4,5);
saveh5(myCxMat,'myCxMat.h5','ComplexFormat',{'myReal','myImag'});
h5disp('myCxMat.h5');
mySavedData = loadh5('myCxMat.h5','ComplexFormat',{'myReal','myImag'});
isequal(mySavedData.myCxMat,myCxMat)

which should output:

HDF5 myCxMat.h5 
Group '/' 
    Dataset 'myCxMat' 
        Size:  4x5
        MaxSize:  4x5
        Datatype:   H5T_COMPOUND
            Member 'myReal':  H5T_IEEE_F64LE (double)
            Member 'myImag':  H5T_IEEE_F64LE (double)
        ChunkSize:  []
        Filters:  none
        FillValue:  H5T_COMPOUND

ans =

  logical

   1
fangq commented 4 years ago

looks great! thanks, accepted.