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
save('matlabfile.mat','data')

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

import scipy.io

# import file into a dictionary
f = scipi.io.loadmat('matlabfile.mat')

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

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

2 thoughts on “Reading Matlab files – Structures

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s