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
@gariepy嗨列表,非常感謝你對你的反應,我真的很感激。不幸的是我仍然無法工作。我很抱歉,但這是我編程或使用Matlab的第一天。 我是否必須輸入整個path_name,例如'D:/ 5 - EEG/EEG Recordings',無論它是否表示路徑名或全路徑名? 爲了使它工作,我應該去:'new-> function'複製並粘貼您的所有代碼。將該函數保存到任何文件夾'SethPath-> AddFolder'。 我得到一個錯誤:「選定的會話無法評估,因爲它包含一個無效的語句」 – Glu
是的,將代碼保存到一個文件,在這種情況下稱爲「run_script_with_loop.m」,因爲MATLAB想要的名稱'函數'來匹配文件名。確保保存文件的文件夾位於matlab路徑中。然後,你應該能夠輸入'%run_script_with_loop('D:\ MATLAB \ eeglab_current \ data_folder')',其中'data_folder'是你的.bdf文件所在的全名。 – gariepy
另外,'...'是爲了表示你的例子中的所有代碼應該放在哪裏。 – gariepy