1

I am working with two different languages i.e. Matlab and python. I created 5 variables in Matlab. Each variable has a size- (150x1) cells as shown below:

enter image description here

Each cell has a size of (128 x (:)) as shown below:

enter image description here

I saved this workspace into a .mat file using -v7.3 which is a hdf5 format.

In python, I loaded the .mat file using h5py. I was able to load the variables but I am unable to extract the values from each variable.

I get this statement "array([[], dtype=object)" but the values are not loaded into the python workspace. I would like to load all the 150 cells o into a variable say A. How do I de-reference the hdf5 reference?

shreyas kamath
  • 425
  • 1
  • 5
  • 14

2 Answers2

3

Maybe you should save the data in a regular hdf5 file. The .mat file is based on hdf5, but it is not a plain hdf5 file.

In MATLAB you can do it natively using http://es.mathworks.com/help/matlab/import_export/exporting-to-hierarchical-data-format-hdf5-files.html

pablo_worker
  • 1,042
  • 9
  • 26
  • Thank you. I will surely consider that.. But is there any possibility of solving this using mat file? – shreyas kamath Jun 07 '16 at 07:44
  • Put sample code to see how you are trying it please. – pablo_worker Jun 07 '16 at 08:34
  • The code is given below: `import h5py ` `f = h5py.File('D:/Thesis/python svm/AFN.mat','r')` I tried the soultions in [link](http://stackoverflow.com/questions/27670149/read-matlab-v7-3-file-into-python-list-of-numpy-arrays-via-h5py) But there the size of the cell was constant. – shreyas kamath Jun 07 '16 at 19:02
0

To de-reference, use:

f[ref]

where f is the h5py.File object and ref is the <HDF5 object reference> object.

See the h5py documentation on references

ndou
  • 1,048
  • 10
  • 15