Subtraction script while ignoring timestamps in subject names

Hi, I would like to produce a script with a subtraction of ERPs subject by subject, across different conditions, e.g.: condition1 subject1 - condition2 subject1, condition1 subject2 - condition2 subject2 etc. (and in some cases I need to subtract the ERPs with an opposite sign, which contain a word "| opposite" after the timestamp which I need to keep not to confuse with the original ERPs since both are in the same directory).

When I try to adapt the script produced by brainstorm, subject names contain timestamps which are unpredictable. Using * instead of the last part of timestamps does not get recognized by brainstorm. How can I proceed to ignore these timestamps?

Here is an example of my script:

% Script generated by Brainstorm (24-Apr-2020)

% Input files
sFiles = {...
'erps_s0001/xxx/data_210316_2118.mat'};
sFiles2 = {...
'erps_s0001/xxx/data_210316_2118_opposite.mat'};

% Start a new report
bst_report('Start', sFiles);

% Process: Difference: A-B
sFiles = bst_process('CallProcess', 'process_diff_ab', sFiles, sFiles2);

% Save and display report
ReportFile = bst_report('Save', sFiles);
bst_report('Open', ReportFile);
% bst_report('Export', ReportFile, ExportDir);

I am trying to change it into:

% Input files
sFiles = {...
'erps_s0001/xxx/data*.mat'};
sFiles2 = {...
'erps_s0001/xxx/data*opposite.mat'};

  • but it doesn't work.

Eventually I would like to enter all subjects in the loop (but so that the subtraction occurs subject by subject).

Thanks a lot for your help!!

You need to select the files with one of the file selection processes before, in order to get the sFiles structures for all you files:

Thanks a lot Francois!
What I don't quite understand - how to script subtractions on the individual subject-by-subject level if subjects' filenames are all collected within sFiles? I need to be sure that condition1 subject1 gets subtracted from condition2 subject1, and not from subject2 or the total subtraction of the average.

Thank you so much for your help!!

From the Process2 tab, the Subtraction process process the files by pairs in the order the files where given in input.

Alternatively, write a script with a loop over the subjects, as illustrated on the Scripting or Group analysis advanced tutorials.