首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >适用于不同数据集的循环和EEGLAB的条件

适用于不同数据集的循环和EEGLAB的条件
EN

Stack Overflow用户
提问于 2016-04-25 18:44:19
回答 1查看 1.4K关注 0票数 1

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

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

所以这些文件被保存为

代码语言:javascript
复制
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循环,但它只是不起作用。

我真的很感谢你的帮助。

这是当前的预处理脚本:

代码语言:javascript
复制
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 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-25 20:38:40

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

代码语言:javascript
复制
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一样,您可以使用通配符获取自定义的文件列表,比如dir('1-*.bdf'),只获取主题1的数据文件列表。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36848619

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档