Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
hdf5 complex double

Subject: hdf5 complex double

From: Thomas

Date: 11 Feb, 2009 16:36:01

Message: 1 of 7

Hi,

I was trying to figure out how I can read complex<double> hdf5 matrices in Matlab.
So far I use the hdf5-1.8.2 library in a c++ programm to write the matrices to disk.
For the element type I use H5::ArrayType(H5::PredType::IEEE_F64LE, 1, (size_t ) 2) (note: this is the c++ wrapper statement).

Is it possible to
1. read this in matlab?
2. map this to matlab complex numbers? How?
3. are there issues with ArrayType between hdf version 1.6.5 (matlab) and 1.8.2 (me)?

I could not even achieve to read in integer matrices. So far all my attempts were in vain.

Thanks a lot,
Thomas

P.S.: The h5dump output looks ok.

Subject: hdf5 complex double

From: Rune Allnor

Date: 11 Feb, 2009 18:07:18

Message: 2 of 7

On 11 Feb, 17:36, "Thomas " <ze...@tfp.uni-karlsruhe.de> wrote:
> Hi,
>
> I was trying to figure out how I can read complex<double> hdf5 matrices in Matlab.
...
> 3. are there issues with ArrayType between hdf version 1.6.5 (matlab) and 1.8.2 (me)?
>
> I could not even achieve to read in integer matrices. So far all my attempts were in vain.

If the data format is supported by matlab, it is a question
for matlab technical support to keep matlab up to date
with these formats.

Until such times that matlab has been updated and you
have got the updated version, you can use a MEX interface
which uses the reading functions from the C++ library.

Rune

Subject: hdf5 complex double

From: Ashish Uthama

Date: 13 Feb, 2009 18:03:49

Message: 3 of 7

On Wed, 11 Feb 2009 11:36:01 -0500, Thomas <zebro@tfp.uni-karlsruhe.de>
wrote:

> Hi,
>
> I was trying to figure out how I can read complex<double> hdf5 matrices
> in Matlab.
> So far I use the hdf5-1.8.2 library in a c++ programm to write the
> matrices to disk.
> For the element type I use H5::ArrayType(H5::PredType::IEEE_F64LE, 1,
> (size_t ) 2) (note: this is the c++ wrapper statement).
>
> Is it possible to
> 1. read this in matlab?

It would help to know which version of MATLAB you are currently using.

> 2. map this to matlab complex numbers? How?
> 3. are there issues with ArrayType between hdf version 1.6.5 (matlab)
> and 1.8.2 (me)?
>
> I could not even achieve to read in integer matrices. So far all my
> attempts were in vain.
>
> Thanks a lot,
> Thomas
>
> P.S.: The h5dump output looks ok.


You could either use HDF5READ or the low level HDF5 library interface
(which is very similar to the C API)

http://www.hdfgroup.uiuc.edu/UserSupport/examples-by-api/api16-m.html

You might have to read it in as two arrays and then convert it into the
MATLAB complex data type.

Subject: hdf5 complex double

From: Thomas

Date: 18 Feb, 2009 10:57:01

Message: 4 of 7

"Ashish Uthama" <first.last@mathworks.com> wrote in message <op.upaxsnkwa5ziv5@uthamaa.dhcp.mathworks.com>...
> On Wed, 11 Feb 2009 11:36:01 -0500, Thomas <zebro@tfp.uni-karlsruhe.de>
> wrote:
> It would help to know which version of MATLAB you are currently using.
I am using Version 7.7.0.471 (R2008b)

> You could either use HDF5READ or the low level HDF5 library interface
> (which is very similar to the C API)
I tried the low level api which is fairly easy but with no different result.

> You might have to read it in as two arrays and then convert it into the
> MATLAB complex data type.
So my question is ... What is the matlab complex data type, how is it stored, how can it be casted?
All my attempts to convert complex data resulted in just ordinary floating point data.

The whole story is:
I want to store std::complex<double> matrices from my c++ program to disk and then read it with matlab to visualize the data.
The complex data is stored in a dataset with array type elements of size two, each containing 64bit foating point numbers (real and imaginary part) .

The h5dump is as follows:

$ h5dump -H testMat.h5
 
HDF5 "testMat.h5" {
GROUP "/" {
   DATASET "data" {
      DATATYPE H5T_ARRAY { [2] H5T_IEEE_F64LE }
      DATASPACE SIMPLE { ( 10, 10 ) / ( 10, 10 ) }
      ATTRIBUTE "datatype" {
         DATATYPE H5T_STRING {
               STRSIZE 1;
               STRPAD H5T_STR_NULLTERM;
               CSET H5T_CSET_ASCII;
               CTYPE H5T_C_S1;
            }
         DATASPACE SIMPLE { ( 15 ) / ( 15 ) }
      }
   }
}
}

That looks okay ... doesn't it?

So after a correct reading ... I would have to combine the real and imaginary part and cast the data to matlab's complex datatype.

Best regards, Thomas

Subject: hdf5 complex double

From: Thomas

Date: 18 Feb, 2009 16:37:01

Message: 5 of 7

Ok .... sorry for all the trouble!

Apparently, it all works fine if you put an awake user in front of the PC. Today, I tried it again and it miraculously worked. After all, I realized that the data is read in some fancy order. In the end, it was only a matter of reshuffling the data in the right order with permute(data, [2 3 1]).

Thanks for the help anyways,

Thomas

Subject: hdf5 complex double

From: Ashish Uthama

Date: 18 Feb, 2009 17:04:01

Message: 6 of 7

On Wed, 18 Feb 2009 11:37:01 -0500, Thomas <zebro@tfp.uni-karlsruhe.de>
wrote:

> Ok .... sorry for all the trouble!
>
> Apparently, it all works fine if you put an awake user in front of the
> PC. Today, I tried it again and it miraculously worked. After all, I
> realized that the data is read in some fancy order. In the end, it was
> only a matter of reshuffling the data in the right order with
> permute(data, [2 3 1]).
>
> Thanks for the help anyways,
>
> Thomas


Glad you worked that out Thomas.

The issue here is the column-major order of elements in memory in MATLAB
(fortran inspired) and the row-major order used in the HDF5 library (C
style).

You can find some more info related to this here:

http://www.hdfgroup.uiuc.edu/UserSupport/examples-by-api/matlab/HDF5_M_Examples/README.txt

(http://www.hdfgroup.uiuc.edu/UserSupport/examples-by-api/api16-m.html)

Subject: hdf5 complex double

From: Ashish Uthama

Date: 18 Feb, 2009 17:05:35

Message: 7 of 7

On Wed, 18 Feb 2009 12:04:01 -0500, Ashish Uthama
<first.last@mathworks.com> wrote:

> On Wed, 18 Feb 2009 11:37:01 -0500, Thomas <zebro@tfp.uni-karlsruhe.de>
> wrote:
>
>> Ok .... sorry for all the trouble!
>>
>> Apparently, it all works fine if you put an awake user in front of the
>> PC. Today, I tried it again and it miraculously worked. After all, I
>> realized that the data is read in some fancy order. In the end, it was
>> only a matter of reshuffling the data in the right order with
>> permute(data, [2 3 1]).
>>
>> Thanks for the help anyways,
>>
>> Thomas
>
>
> Glad you worked that out Thomas.
>
> The issue here is the column-major order of elements in memory in MATLAB
> (fortran inspired) and the row-major order used in the HDF5 library (C
> style).
>
> You can find some more info related to this here:
>
> http://www.hdfgroup.uiuc.edu/UserSupport/examples-by-api/matlab/HDF5_M_Examples/README.txt
>
> (http://www.hdfgroup.uiuc.edu/UserSupport/examples-by-api/api16-m.html)


Specifically, look at point 4.
Flipping the dimensions using the lower level interface would be more
efficient than permuting the result when dealing with large data sets.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us