I have few MATLAB variables of following datafields which I saved in test.mat file using -v7.3 flag and want to read back using h5py module for other purpose.
load('test.mat'); % give me this
struct with fields:
volume: [4240×1 double]
centroid: [4240×3 double]
faces: {4240×1 cell}
nuc: {4240×1 cell}
I can read the double field variable but unable to access the cell fields variable. Is therey any way I can access nuc and faces variable from python?
>>>import h5py
>>>name='test.mat'
>>>f=h5py.File(name)
>>>f.keys()
<KeysViewHDF5 ['#refs#', 'volume', 'centroid', 'faces', 'nuc']>
>>>o1=f['centroid']
<HDF5 dataset "centroid": shape (3, 4240), type "<f8">
>>>o1[:,0]
array([ -387.82973928, 533.54789111, -7359.64917621])
>>>o3=f['nuc']
<HDF5 dataset "nuc": shape (1, 4240), type "|O">
>>>type(o3)
<class 'h5py._hl.dataset.Dataset'>
>>>type(o3[0])
<class 'numpy.ndarray'>
>>>type(o3[0][0])
<class 'h5py.h5r.Reference'>
>>>o3[0][0]
<HDF5 object reference>
>>>o3[0]
array([<HDF5 object reference>, <HDF5 object reference>,
<HDF5 object reference>, ..., <HDF5 object reference>,
<HDF5 object reference>, <HDF5 object reference>], dtype=object)
I tried all the option but I cannot see the numerical values of nuc variable. Any suggestion will be appreciated.
Thanks for the comment everyone. Following command is working now.
>>> f[f['nuc'][0][0]][:]
array([[ -733.94435313, -733.66995189, -734.09632262, ...,
-733.66832197, -733.81233202, -733.54615564],
[ 247.76823184, 247.49908481, 248.17514583, ...,
240.16088783, 240.56909865, 240.84810507],
[-7485.86866961, -7485.92114207, -7485.93468626, ...,
-7508.16909395, -7508.16306386, -7508.20712349]])
>>> f[f['nuc'][0][0]][:].shape
(3, 1512)
>>> f[f['nuc'][0][1]][:].shape
(3, 1491)
>>> f[f['nuc'][0][2]][:].shape
(3, 1556)