[Eeglablist] epoching via a loop in a script

William McGeown william.mcgeown at strath.ac.uk
Thu Oct 19 08:06:23 PDT 2023


Dear All,
I was wondering how I might define a list of conditions (single and combined) for epoching, then loop through to create separate files for each condition or combination of conditions.
In the example below I would like to generate separate files for conditions 1, 2 and 3, and a file that contains conditions 2 AND 3.

I can do this for single conditions by indexing the dataset before epoching e.g., as dataset 1 (then I can return to it to epoch the next condition as specified in the list).
and defining a subj_id (e.g., 'P001')
Then I can run code such as:

data_before_epoching = 1 %index the dataset to return to before running pop_epoch each time

conditions= [1 2 3] %list of conditions

for condition = conditions
    [ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET,'retrieve',dataset_before_epoching,'study',0);EEG = eeg_checkset(EEG);
    [EEG] = pop_epoch( EEG, {condition}, [-.150 .8], 'newname', [subj_id,'epochs'], 'epochinfo', 'yes');
    [ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG);
    eeglab redraw
end


That works as expected (and I would e.g., fill out the loop more to save data, etc), but I run into problems if I want to use pop_epoch with a combination of conditions (see below).  I'm not sure how to do this within a script, by calling a variable.  Perhaps I can store the condition information in a cell such as:


data_before_epoching = 1 %index the dataset to return to before running pop_epoch each time
conditions = {1, 2, 3, [2, 3]}

for condition = conditions
    [ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET,'retrieve',dataset_before_epoching,'study',0);EEG = eeg_checkset(EEG);
    [EEG] = pop_epoch( EEG, {condition{:}}, [-.100 .8], 'newname', [subj_id,'epochs'], 'epochinfo', 'yes');
    [ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG);
    eeglab redraw
end


This gives the error:
Arrays have incompatible sizes for this operation.

Error in pop_epoch (line 247)
                        Ieventtmp = [ Ieventtmp find(tmpevent == [ tmpeventtype{:} ]) ];

Error in epoch_extraction_tests (line 21)
    [EEG] = pop_epoch( EEG, {condition{:}}, [-.100 .8], 'newname', [subj_id,'epochs'], 'epochinfo', 'yes');


Could you please let me know how I can solve this issue and ensure the correct input to the function (pop_epoch) for my condition list?
(I don't know if the issue is being caused by the Neuroscan .cnt import which means that the EEG.event.type in the datastructure are all numerical (the class is listed as char), and the function is trying to check if the event is present in that list and it expects a single number rather than 2 numbers as provided by the cell (in the example above), or if it is simply that I am unsure about how to get the information from the cell and pull it into the function.
In this example I could get the result for conditions 2 AND 3 by running this:
 [EEG] = pop_epoch( EEG, {2 3}, [-.150 .8], 'newname', [subj_id,'epochs'], 'epochinfo', 'yes');
But I would like to specify the conditions in a list and then loop through it.

Thank you,

Will



More information about the eeglablist mailing list