针对EEGLAB

时间:2016-04-25 18:44:19

标签: matlab for-loop eeglab

我必须分析一些EEG数据,我正在尝试自动化预处理程序。

我有40个参与者。每个参与者有4个不同的文件,有4个条件。

所以文件保存为

1-1  
1-2  
1-3  
1-4  
2-1  
2-2  
2-3  
2-4  
...  

高达40-4

这些文件来自BioSemi(.bdf)

我已经能够自动化预处理过程,但每次我必须选择不同的文件时,运行脚本并保存。

我想运行一个for循环来完成所有这一切(取1-1,运行预处理,保存,取1-2 ......等)。

我正在粘贴到目前为止我所拥有的东西。

我一直在努力写一个for循环,但它只是不起作用。

我真的很感激任何帮助。

这是当前的预处理脚本:

subject = '1-1.bdf'  

%Open EEGLAB and inizialize several EEGLAB variables (listed in the output
%function  
[ALLEEG EEG CURRENTSET ALLCOM] = eeglab;  

%Load a file  
%EEG=pop_loadset;  % pop up window to input arguments  

EEG = pop_biosig(subject)  %Reads in the dataset frin a BIOSEMI file  

% Stores the dataset into EEGLAB  
[ALLEEG EEG CURRENTSET ] = eeg_store(ALLEEG, EEG);  

%Change sampling rate to 512  
EEG = eeg_checkset( EEG );    
EEG = pop_resample( EEG, 512);    
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET); %save it as a new dataset  

% Edit Channel Location  
EEG = eeg_checkset( EEG );  
EEG=pop_chanedit(EEG, 'lookup','D:\\Matlab\\eeglab_current\\eeglab13_5_4b\\plugins\\dipfit2.3\\standard_BESA\\standard-10-5-cap385.elp');  
% Store the dataset into EEGLAB  
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 2,'overwrite','on','gui','off');  

% Add some comments  
EEG.comments = pop_comments(EEG.comments,'','Sampling rate was changed to 512.',1);  
% You can see the comments stored with the dataset either by typing >> EEG.comments or selecting the menu option Edit->About this dataset.  

%Select Data. Remove EXG5:EXG8   
EEG = eeg_checkset( EEG );  
EEG = pop_select( EEG,'nochannel',{'EXG5' 'EXG6' 'EXG7' 'EXG8'});  
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 2,'overwrite','on','gui','off');  


%HighPassFilter 0.5  
EEG = eeg_checkset( EEG );  
EEG = pop_eegfilt( EEG, 0.5, 0, [], [0], 0, 0, 'fir1', 0);  
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 2,'overwrite','on','gui','off');  

%LowPassFilter 50  
EEG = eeg_checkset( EEG );  
EEG = pop_eegfilt( EEG, 0, 50, [], [0], 0, 0, 'fir1', 0);  
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 2,'overwrite','on','gui','off');  


%ReReference to 35 36 (EXG3. EXG4)  
EEG = eeg_checkset( EEG );  
EEG = pop_reref( EEG, [35 36] );  
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 2,'overwrite','on','gui','off');   

% Reject Continuous By Eye  
EEG = eeg_checkset( EEG );  
pop_eegplot( EEG, 1, 0, 1);  

eeglab redraw % Update the EEGLAB window to view changes  

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Automatic Channel Rejection  
EEG = eeg_checkset( EEG );  
EEG = pop_rejchan(EEG, 'elec',[1:34]   ,'threshold',5,'norm','on','measure','prob');  
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 2,'overwrite','on','gui','off');  

eeglab redraw % Update the EEGLAB window to view changes 

1 个答案:

答案 0 :(得分:1)

以下是如何在循环中访问文件名,以便您可以运行MATLAB脚本。最简单的方法是将.bdf文件放在一个文件夹中。然后编写一个包含所需功能的函数,如下所示:

function run_script_with_loop(pathname)

file_struct_list = dir([pathname filesep() '*.bdf']);  %% get list of .bdf files in the pathname specified

filename_list = {file_struct_list.name};  %% extract the filenames into a cellarray
for subject = filename_list  %% this iterates over the elements of the cell array, one-by-one, setting the `filename` variable like a loop variable
    [ALLEEG EEG CURRENTSET ALLCOM] = eeglab;  
    full_pathname = [pathname filesep() subject{1}];
    EEG = pop_biosig(full_pathname);  %% perform your processing
    ...
end

一些评论:

  • 我试图通过使用filesep()来与平台无关 这应该适用于linux / mac / windows。如果您正在运行代码 在与数据文件相同的目录中,您当然可以简化 此

  • 取消引用{}时,请务必使用花括号subject。如果您使用带有subject(1)的标准matlab数组引用,那么您将获得一个包含文件名字符串的单元格数组,而不仅仅是纯文件名字符串

  • MATLAB中的dir()命令就像Windows中的dir或Linux中的ls一样,您可以使用通配符来获取文件的自定义列表,例如{{ 1}}仅获取主题1的数据文件列表