I would like to convert a complex MAT file that include numbers, structs, arrays and array of nested structs, in which those structs could have their "mother" contents types, into a Python dictionary of a same hierarchical shape.
Found a converter for similar case on this link which originally written for Python 2.7. However, this converter does not support array of structs.
A representative sample MAT file could be created using the follow Matlab script:
item11 = 11;
item12 = '12';
item21 = 21;
item22 = '22';
struct1.item1 = item11;
struct1.item2 = item12;
struct2.item1 = item21;
struct2.item2 = item22;
ar = [struct1, struct2];
By altering the similar case on this example and adding a check whether an array contains Matlab object
scipy.io.matlab._mio5_params.mat_struct
, and if it does, recursively convert its contents and save it into alist
object. The solution can support 1D array of structs.Conversion functions:
The above sample resulting after conversion: