hd5f to access to nested structures in *.mat files
See original GitHub issueGeneral information
- Operating System (e.g. Windows 10, MacOS 10.11, Ubuntu 16.04.2 LTS, CentOS 7): Windows 10
- Python version (e.g. 2.7, 3.5): 3.7.3
- Where Python was acquired (e.g. system Python on MacOS or Linux, Anaconda on Windows): Anaconda
- h5py version (e.g. 2.6): 2.9
- HDF5 version (e.g. 1.8.17) 1.10.4
- The full traceback/stack trace shown (if it appears)
I getting access to the following structure of matlab file (*.mat):
which contains the following set of structures:
I try to access to the fields inside each structure using hd5f python lib
using the following code:
mat_dict = h5py.File(file_path, 'r')
result = mat_dict['JKPRR']['results']['ChangingKnob'][0]['result']
But apparently I can’t go deep from:
result = mat_dict['JKPRR']['results']['ChangingKnob'][0]
Do you know how I can go to the deeper fields?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
How to use hd5f to access to nested structures in *.mat files?
Solution & discussion in following issue: https://github.com/h5py/h5py/issues/1668. First, the easy bit: it looks like the ChangingKnob ...
Read more >How to use hd5f to access to nested structures in *.mat files?
I try to get access to the following structure of matlab file (*.mat):. parent matlab structure. which contains the following set of structures....
Read more >Access Data in Nested Structures - MATLAB & Simulink
This example shows how to index into a structure that is nested within another structure. The general syntax for accessing data in a...
Read more >How to use HDF5 files in Python
Each HDF5 file has an internal structure that allows you to search for a specific dataset. You can think of it as a...
Read more >Read complex .mat files - PyHOGS
The function below loads a . mat file and converts the nested scalar structures into nested dictionaries. If you aren't using arrays of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
First, the easy bit: it looks like the
ChangingKnob
dataset is 2D, so to get one item out, you need two indices:It looks like Matlab is storing HDF5 references (a kind of link) in the dataset, so then you need to follow the reference:
Hopefully after that you can do
dataset['result']
to access one field, unless Matlab has made more obstacles.Closing this as it looks (from the 👍) like it’s resolved. We can continue the discussion or reopen it if needed.
To summarise for other people looking at this: Matlab’s
.mat
files do appear to be HDF5, but they might be oddly structured and require some fiddling to work out how to get the data you want. You may want to use a HDF viewer tool like HDFview or h5glance to inspect it.