如何在python中读写和存储matlab的数据文件(*.mat)

使用sicpy.io即可.sicpy.io提供了两个函数loadmat和savemat,非常方便.

import scipy.io as sio  
import matplotlib.pyplot as plt  
import numpy as np  

#matlab文件名  
matfn=u'E:/python/测试程序/162250671_162251656_1244.mat'  
data=sio.loadmat(matfn)  

plt.close('all')  
xi=data['xi']  
yi=data['yi']  
ui=data['ui']  
vi=data['vi']  
plt.figure(1)  
plt.quiver( xi[::5,::5],yi[::5,::5],ui[::5,::5],vi[::5,::5])  
plt.figure(2)  
plt.contourf(xi,yi,ui)  
plt.show()  

sio.savemat('saveddata.mat', {'xi': xi,'yi': yi,'ui': ui,'vi': vi}) 

你可能感兴趣的:(Python,python,matlab)