mat4py
mat4py copied to clipboard
Issue loading structs saved by Octave
Saving a simple test struct created in Octave
a.b = 1;
save -v7 test.mat a
and loading with loadmat
loadmat('test.mat')
returns the error
\temp\loadmat.py in read_struct_array(fd, endian, header)
315 if field_name_length > 32:
316 raise ParseError('Unexpected field name length: {}'.format(
--> 317 field_name_length))
318
319 # read field names
ParseError: Unexpected field name length: 64
scalars work fine though, and importing structs from Matlab instead of Octave (as well as loading the test.mat file into Matlab).
Does it work with SciPy's loadmat?
from scipy.io import loadmat
loadmat('test.mat')
Yes, that seems to work fine.
loadmat('test.mat')
{'__header__': b'MATLAB 5.0 MAT-file, written by Octave 6.2.0, 2021-03-12 10:01:17 UTC', '__version__': '1.0', '__globals__': [], 'a': array([[(array([[1.]]),)]], dtype=[('b', 'O')])}
It could be something with Matlab using the "small data element format" while I think Octave does not.
https://www.mathworks.com/help/pdf_doc/matlab/matfile_format.pdf (page 1-7)