Problem with writing EEGlab script

21 views (last 30 days)
Subin Lee
Subin Lee on 19 Dec 2014
Edited: Subin Lee on 19 Dec 2014
Hi, I'm trying to write a script that will carry out all the steps in EEGlab from selecting data and channel locations to averaging ERP. However, I keep having a problem at the end with 'pop_averager' with an error that says: -----------------
Undefined function or variable 'EEG'.
Error in pop_averager (line 259) p.parse(EEG, varargin{:});
Error in erpscript3 (line 69) ERP = pop_averager( EEG , 'Criterion', 'good', 'DSindex', 7, 'ExcludeBoundary', 'on', 'SEM', 'on' ); --------------------------
Below between the double lines is the script that I wrote: Btw, ksy is the subject's name and the number after it is the session number. I am trying to compute the average of the erps of each session. The script works fine until the part at the end which are in asterisks here and is about the pop_averager.
===========================================================
clear
clc
[ALLEEG EEG CURRENTSET ALLCOM] = eeglab;
save_everything = 1;
subject_list = {'ksy1','ksy2','ksy3','ksy4','ksy5','ksy6','ksy7'};
numsubjects = length(subject_list);
parentfolder = 'C:\Users\SubinLee\Documents\MATLAB\ERP\Task5SubjectRawData\';
outputfolder = 'C:\Users\SubinLee\Documents\MATLAB\ERP\Task5WIPfolder\';
ALLEEG = buildERPstruct([]);
for s=1:numsubjects
subject = subject_list{s};
subjectfolder = [parentfolder ];
fprintf('\n\n\n***Processing subject %d (%s)***\n\n\n',s,subject);
%Load .set and save as
EEG = pop_loadset('filename',[subject '.set'],'filepath',subjectfolder);
EEG.setname=[subject '.set'];
%exclude channels
EEG = pop_select( EEG,'nochannel',{'EKG1' 'BR'});
EEG.setname=[subject '_66'];
%chanel location
EEG = pop_chanedit(EEG, 'lookup','C:\\Users\\SubinLee\\Documents\\MATLAB\\ERP\\64CH w EOGs_KLee.ced');
%rereference and exclude eog
EEG = pop_reref( EEG, [33 43] ,'exclude',[65 66] );
EEG.setname=[subject '_66chan64'];
%change sampling rate
EEG = pop_resample( EEG, 500);
EEG.setname=[subject '_done'];
EEG = pop_saveset( EEG,'filename',[subject '_done.set'],'filepath',outputfolder);
%create eventlist-advanced-load as'1020list.txt'-ok
EEG = pop_editeventlist( EEG , 'AlphanumericCleaning', 'on', 'BoundaryNumeric', { -99}, 'BoundaryString', { 'boundary' },'List', 'C:\Users\SubinLee\Documents\MATLAB\ERP\Task5SubjectRawData\1020list.txt', 'SendEL2', 'EEG&Text', 'UpdateEEG', 'off', 'Warning', 'off' );
EEG.setname=[subject '_done_elist.set'];
if (save_everything)
EEG = pop_saveset( EEG,'filename',[subject '_done_elist.set'],'filepath',outputfolder);
end
%bin-based epoching
EEG = pop_epochbin( EEG , [-200.0 800.0], 'pre');
EEG.setname=[subject '_done_elistbe.set'];
if (save_everything)
EEG = pop_saveset( EEG,'filename',[subject '_done_elistbe.set'],'filepath',outputfolder);
end
%artifact detection wwppth
EEG = pop_artmwppth( EEG , 'Channel', 1:64, 'Flag', 1, 'Review', 'off', 'Threshold', 100, 'Twindow', [ -200 798], 'Windowsize', 200, 'Windowstep', 50 );
EEG.setname=[subject '_done_elistbe_ar.set'];
EEG = pop_saveset( EEG,'filename',[subject '_done_elistbe_ar.set'],'filepath',outputfolder);
%Allows _done_elistbe_ar.set to be visualized as dataset on GUI
[ALLEEG EEG] = eeg_store( ALLEEG, EEG, s );
%average
*ERP = pop_averager( ALLEEG , 'Criterion', 'good', 'DSindex', 7, 'ExcludeBoundary', 'on', 'SEM', 'on' );*
ERP= pop_savemyerp(ERP, 'erpname', [subject '_ERPs.set'], 'filename', [subject '_ERPs.erp']);
end
%shows datasets on GUI
eeglab redraw;
========================================================================= The script works fine until it gets to the pop_averager part. To avoid this problem, I have tried carrying out the script only up to the resmpaling part, then doing everything else (epoching, etc) through the gui. But even on the gui, when I try to compute the average, the same error as above pops up.
What exactly does p.parse and varargin mean? An how can I solve this problem?
Thanks, Subin

Answers (0)

Categories

Find more on EEG/MEG/ECoG in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!