swetha swetha - 29 days ago 6
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.

D=load('tst.mat','dict');


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

Answer

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.

Comments