matlab代码运行文件夹内的数据并将数据保存

来源:互联网 发布:深圳淘宝代运营 编辑:程序博客网 时间:2024/06/08 06:51

将文件夹内的数据载入,调用函数eeg_SampEn_Run02()进行处理,之后将结果保存到文本文档中(使用的是绝对路径)。
代码如下:

%Num. 01%E:\mwork\SampEn\eegdatas\normal\eyeclosed\c3txtpath_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文件endfclose(fp_normal_eyeclosed_c3);%关闭文件,写在for后面fprintf('normal_eyeclosed_c3_over\n');%运行结束%normal_eyeclosed_c3_over
0 0
原创粉丝点击