1

I'm trying to read a matlab .mat file (v7.3) from python. The thing is one of the field in the .mat object is a table (7x6) with named columns, and every time I read the object I only get a 1x6 array with random numbers. I've tried with the h5py and pymatreader libraries but it didn't work.

How to correctly read the matlab .mat in Python?

I'm adding a minimal working example.

So from the Matlab code:

test_table = table([1, 2]', [3, 4]', VariableNames={'a', 'b'});
save("test_table_73.mat", "test_table", "-v7.3");

And the python code to read it:

import mat73

data_73 = mat73.loadmat("test_table_73.mat")
print(data_73)

The python code output

{'test_table': None}
ERROR:root:ERROR: MATLAB type not supported: table, (uint32)
4
  • You should share the sample .mat file here to understand the input better. However, normally mat73 is good in all these. Posted as an answer Commented Sep 19 at 20:19
  • Please, take some time to read how to ask and How to create a Minimal, Reproducible Example Commented Sep 19 at 20:58
  • Did you try pymatreader? Commented Sep 23 at 12:19
  • @CrisLuengo pymatreader kinda works. It gives me a dict with the keys 'test_table' and '#subsystem#' 'test_table' is just a random array, while under subsystem there is the key 'MCOS' wich is a list. data_73['#subsystem#']['MCOS'][2] gives me the array and data_73['#subsystem#']['MCOS'][7] gives me the VariableNames in the table. This works because it's a .mat file containing a single variable, but if the .mat file was bigger it will contain way too many stuff under 'MCOS' Commented Sep 23 at 14:24

1 Answer 1

0

As stated in the comment, please try this. It might help

from mat73 import loadmat
data = loadmat('your_file.mat')
table = data['your_table_name']  # Replace with actual key
print(table)
Sign up to request clarification or add additional context in comments.

3 Comments

It's not working, I get ERROR:root:ERROR: MATLAB type not supported: table, (uint32) {'T_PRT': None}
Did you try importing directly? import mat73.
The mat73 package explicitly states that only the basic data types are supported, there’s a list of types you can load from the MAT-file. github.com/skjerns/mat7.3?tab=readme-ov-file#datatypes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.