将文件夹内的数据载入,调用函数eeg_SampEn_Run02()进行处理,之后将结果保存到文本文档中(使用的是绝对路径)。
代码如下:
%Num. 01
%E:\mwork\SampEn\eegdatas\normal\eyeclosed\c3
txtpath_normal_eyeclosed_c3 = 'E:\mwork\SampEn\eegdatas\normal\eyeclosed\c3\';%原始文件读取路径
dir_normal_eyeclosed_c3 = dir([txtpath_normal_eyeclosed_c3,'*.txt']);%返回文件夹中所有的txt文件
%打开实验结果文件,写在for前面
fp_normal_eyeclosed_c3 = fopen('E:\mwork\SampEn\eegResult\Result_normal_eyeclosed_c3.txt','wt');
for i = 1:length(dir_normal_eyeclosed_c3)
data_normal_eyeclosed_c3 = fopen([txtpath_normal_eyeclosed_c3,dir_normal_eyeclosed_c3(i).name],'r');%根据文件名读取txt文件
eegdata_normal_eyeclosed_c3 = fscanf(data_normal_eyeclosed_c3,'%d');%读取txt文件,将每个文本逐一读取到tdata
fclose(data_normal_eyeclosed_c3);
SampEn = eeg_SampEn_Run02(eegdata_normal_eyeclosed_c3);%调用函数eeg_SampEn_Run02,求熵值
fprintf(fp_normal_eyeclosed_c3,'SampEn_normal_eyeclosed_c3 = %d\n',SampEn);%写入到txt文件
end
fclose(fp_normal_eyeclosed_c3);%关闭文件,写在for后面
fprintf('normal_eyeclosed_c3_over\n');%运行结束
%normal_eyeclosed_c3_over
该博客介绍如何使用Matlab加载文件夹中的数据,应用特定函数处理后,将处理结果保存到文本文档。主要涉及Matlab的数据读取、函数应用及文件保存操作。
523

被折叠的 条评论
为什么被折叠?



