1

我必须分析一些脑电图数据,并且我正在尝试自动化预处理过程。

我有 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 
4

1 回答 1

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。如果您将标准 matlab 数组引用与 一起使用subject(1),那么您将获得一个包含文件名字符串的元胞数组,而不仅仅是普通的文件名字符串

  • MATLAB 中的命令与windows 或 Linux 中的dir()命令一样,您可以使用通配符获取自定义文件列表,例如仅获取主题 1 的数据文件列表dirlsdir('1-*.bdf')

于 2016-04-25T20:38:40.990 回答