Importing MEG/EEG: Events question

Method 1 is not working, as the nested for loops do not select specific files from the inputs

Method 2 seems more appropriated, and in fact it can be automated. Any repetitive task is a task for code rather for people :slight_smile:

The approach would be to find all the recoding files for a given Subject and a given Condition (folder). The automated Method 2 will do these tasks:

  • For every Subject in Subjects
    • For every Condition in Conditions
      • Find / Select Trials in Condition
      • Run custom process on Trials in Condition

The code would look like:

% Subject names
SubjectNames = {'UD14', 'UD15'};
% Condition name after "_" . It assumes same condition name endings for all Subjects
Conditions   = {'1kQ45', '1kQ60'}; 

for iSubject = 1 : length(SubjectNames)
    subjectName = SubjectNames{iSubject};
    for iCondition = 1 : length(Conditions)
        conditionName = [subjectName, '_', Conditions{iCondition}];
        % Process: Select data files
        sFiles = bst_process('CallProcess', 'process_select_files_data', [], [], ...
            'subjectname',   subjectName, ...
            'condition',     conditionName, ... 
            'tag',           '', ...
            'includebad',    0, ...
            'includeintra',  0, ...
            'includecommon', 0);
        
        % Check selected files
        if isempty(sFiles)
            warning('No files were selected for Subject: "%s", Condition: "%s"\n', subjectName, conditionName);
        else
            fprintf('Selected files for Subject: "%s", Condition: "%s"\n', subjectName, conditionName);
            fprintf('%s\n', sFiles.FileName)
        end
        
        % Process: WAvg RNoise NEpoch
        sFiles = bst_process('CallProcess', 'process_wavg_rnoise_nepoch', sFiles, [], 'info', []);        
    end
end