动态导入不连续mat文件
**提取被试编号**
Subject_class = [‘1’, ‘3’, ‘4’, ‘5’, ‘7’]; # subjects;
#法一
for subject in Subject_class:
print ‘当前被试 :’, subject
代码示例
运行结果
**法二**
for i in range(len(Subject_class)):
# print i+1, Subject_class[i]
print("当前被试 :", i + 1, '数据编号 :', Subject_class[i])
# 动态提取数据文件位置
data_train_dir = 'D:\\...' + 'sub' + str(Subject_class[i]) +'.mat'
print('训练数据 :', data_train_dir)
data_test_dir = 'D:\\...' + 'sub' + str(Subject_class[i])+'.mat'
print('测试数据 :', data_test_dir)
# 导入数据
x_traindata = scipy.io.loadmat(data_train_dir)
x_testdata = scipy.io.loadmat(data_test_dir);
# 至此,动态提取数据成功;