swetha swetha - 1 year ago 64
Python Question

loading .mat file generated with python in matlab

from scipy.io import savemat
import numpy as np

Alist = {fx: [] for fx in stringarr}
A = np.array([2.0, 3.0, 4.0, 5.0])
A = A.reshape(2, 2)
B = [3, 4]
C = [5, 6]
dict_A = {'0': B * A, '1': C * A}
savemat('tst.mat', {'dict': dict_A})

The .mat file is created, but when I load it into matlab.


I get
is a struct with no fields. How do I get this dict into a structure in matlab?

Answer Source

The problem is with the keys '0' and '1'. MATLAB structs cannot have numbers as field names, and MATLAB will silently ignore any struct fields with invalid names like that. So you need to make sure your dict keys conform to MATLAB variable naming rules.