EEGLAB

2016-04-25 31 views
1

For循環不同的數據集和條件我必須分析一些EEG數據,我試圖自動化預處理程序。EEGLAB

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

這裏是你如何可以訪問文件名在一個循環,這樣就可以運行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()命令工作就像dir在窗口或ls在Linux中,你可以使用通配符來獲取文件的自定義列表,就像dir('1-*.bdf')只得到標的1的數據文件

+0

@gariepy嗨列表,非常感謝你對你的反應,我真的很感激。不幸的是我仍然無法工作。我很抱歉,但這是我編程或使用Matlab的第一天。 我是否必須輸入整個path_name,例如'D:/ 5 - EEG/EEG Recordings',無論它是否表示路徑名或全路徑名? 爲了使它工作,我應該去:'new-> function'複製並粘貼您的所有代碼。將該函數保存到任何文件夾'SethPath-> AddFolder'。 我得到一個錯誤:「選定的會話無法評估,因爲它包含一個無效的語句」 – Glu

+0

是的,將代碼保存到一個文件,在這種情況下稱爲「run_script_with_loop.m」,因爲MATLAB想要的名稱'函數'來匹配文件名。確保保存文件的文件夾位於matlab路徑中。然後,你應該能夠輸入'%run_script_with_loop('D:\ MATLAB \ eeglab_current \ data_folder')',其中'data_folder'是你的.bdf文件所在的全名。 – gariepy

+0

另外,'...'是爲了表示你的例子中的所有代碼應該放在哪裏。 – gariepy