demand
Import the data .mat file saved in matlab into python for data analysis.
achieve
After searching, there are ready-made interfaces that can be called:scipy.io.loadmat(filename)
Examples
There are two variables I0 and I1 in test_data.mat, which is a 5000 * 800 matrix.
The purpose is to import the data file into big python and extract I0 and I1.
code show as below:
from scipy.io import loadmat
file = 'C:\\data\test_data.mat'
# mat_dtype=True,保证了导入后变量的数据类型与原类型一致。
data = loadmat(file, mat_dtype=True)
# 导入后的data是一个字典,取出想要的变量字段即可。
I0 = data['I0']
I1 = data['I1']
result:
>>I0.shape
(5000, 800)
>>I0.dtype
float64