诛仙小说结局:solem's vision blog: Reading and writing .mat files with Python

来源:百度文库 编辑:九乡新闻网 时间:2024/07/14 19:50:49

Reading and writing .mat files with Python

If you have some old data, or find some interesting data set online,stored in Matlab's .mat file format it is possible to read this usingthe scipy.io module in SciPy. This is how to do it.

data = scipy.io.loadmat('test.mat')

"data"now contains a dictionary with keys corresponding to the variable namessaved in the original .mat file. The variables are in array format.Saving to .mat files is equally simple. Just create a dictionary withall variables you want to save and use savemat().

data = {}
data['x'] = x
scipy.io.savemat('test.mat',data)

This saves the array x so that it has the name "x" when read into Matlab. More information on scipy.io can be found in the online documentation.