有些人在做脑电实验的时候喜欢起一些奇奇怪怪的名字,这就导致某些数据可能在导入的时候报错,可是错已经犯下了,就改呗,这里刚好有需要,便写了一个批量更改数据名称的代码,其实也非常简单,但是仅针对于只有一个文件的脑电格式,如.edf;.cnt这些可以直接改文件名的脑电文件
而像.vhdr+.eeg+.vmark这种绑定式的文件就不建议更改
此脚本对其它文件依然有用
%
% Written By Yizhou
% Using the code without proper understanding the code and relevant background
% of EEG may lead to confusion, incorrect data analyses,or misinterpretations
% of results.
% The author assumes NO responsibility for inappropriate or incorrect use
% of this code.
% WX: 17373158786
%定义一个路径
dir_path = 'D\一个路径';
%获取当前路径下的所有原始文件名
files = dir([dir_path,filesep,'*.edf']);
%以防无法对应到原始文件,这里保存原始文件名,序号与文件读取顺序对应
xlswrite('files.xls',{files.name}');
for i=1:length(files);
waitbar(i/length(files),'Dont touch me!!');%弹窗提示进度
% 旧的名称
oldname = files(i).name;
%定义一个新的名称
new_name = ['Sub_',num2str(i,'%03d'),'.edf'];
%此处使用的movefile本质上是一个剪切以实现重命名的目的,如果文件过多,或者硬盘性能过低,可能会比较慢;
movefile(oldname, new_name);
end
close all; %关闭弹窗
PS:养成良好的文件命名习惯,非常重要!