I have MATLAB data files which contain multiple structs within struct that i want to import into python. In MATLAB, if main_struct is the main file, I can get down to the data I need by -
leaf1 = main_struct.tree1.leaf1
leaf2 = main_struct.tree1.leaf2
and so on. Now I want to import the .mat file containing struct in python and access leaf1 and leaf2. In python, I can load the mat files -
import scipy.io as sio
data = sio.loadmat("main_struct.mat",squeeze_me=True, struct_as_record=False);
tree1 = data.['tree1'];
How do I access the second struct in tree1 ?
type()- which tells you what kind of object you have (dict, list, etc.) anddir()- which shows you the attributes, both built-in and user-defined. These two functions can help you "explore" an imported object and figure out exactly how to dereference it.tree = data['tree1'](no dot betweendataand[)