静息态数据在处理过程中通常需要分段,一般会进行2s一段的切分,但是可能在后面的分析中这种分段方式不太适用,需要拼接成连续分段或者重新分段,此段代码就用于对数据进行拼接(重新分段)
代码运行环境Matlab 2013B + eeglab13
%% 重新分段
% Written By Zhouyi
% 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
clear;
dir_path = 'D:\Docu\Work\1_Projects\tim_freq_12K\anal_data\Neg_rest';
cd(dir_path);
files = dir([dir_path,filesep,'ref_A12_*.set']); % 此处是已经分过段的数据
for subj = 1:length(files)
EEG = pop_loadset(files(subj).name,dir_path); % 载入一个分段后的数据
parfor i = 1:length(EEG.epoch)
ALLEEG(i) = pop_selectevent( EEG, 'epoch',i,'deleteevents','off','deleteepochs','on','invertepochs','off'); % 用AllEEG结构体储存每个分段的EEG数据
end
EEG = pop_mergeset( ALLEEG, [1:length(EEG.epoch)], 0); % 把每个分段的数据用pop_mergeset 重新拼接成连续数据
EEG.event = []; % 因为之前静息态分段用的maker还保存在数据中,此处清除掉这些maker;
EEG = eeg_regepochs(EEG, 'recurrence', 0.5, 'limits',[0 0.5], 'rmbase',NaN); % 重新分段,按需要进行
EEG = pop_saveset( EEG, 'filename',['re_epoch_E5_',files(subj).name(end-5:end)],'filepath',dir_path); % 保存重新分段后的数据;
end