Reading Matlab files – Structures

Suppose you have saved a structure called “data” in matlab:

% "x" and "y" are two fields in the structure "data"
data.x = linspace(1,100,100);
data.y = linspace(1,100,100);

% save a .mat file

To read “x” and “y” into python:


# import file into a dictionary
f ='matlabfile.mat')

# read in the structure
data = f['data']

# get the fields
x = data[0,0]['x']
y = data[0,0]['y']