Events > Import from file on a loop

Hi there,

I have 172 nap EEG data (continuous raw data ".mat" file) with their corresponding 172 ".csv" files each containing sleep spindle data for the corresponding nap data. Using the process "event > Import from file" I would like to import the 172 ".csv" files into each nap data. That is, the first ".mat" file should contain spindle data from the first ".csv" file, and so on for the second, third, etc.

As there are 172 data ".mat" and ".csv" files I think it's better to use a script rather than doing this manually. I have attempted to generate the below code (based on the MATLAB script generated by Brainstorm) as shown below but would like your help on this. What needs to be amended?

% Input files
sFiles = {...
    'X.mat', ...
    'Y.mat', ...
    'Z.mat'};
RawFiles = {...
    'X.csv', ...
    'Y.csv', ...
    'Z.csv'};

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

for i = 1 : length(sFiles)
    isFile = sFiles{i};
    iRawFile = RawFiles{i};

% Process: Import from file
sFiles = bst_process('CallProcess', 'process_evt_import', isFile, [], ...
    'evtfile', {iRawFile, 'CSV-TIME'}, ...
    'evtname', '', ...
    'delete',  0);
end
sFiles = bst_process('CallProcess', 'process_evt_import', isFile, [], ...

The problem is that sFiles is being reset. You could just ommit the output of the process:

bst_process('CallProcess', 'process_evt_import', isFile, [], ...
1 Like