Custom processing for epoch weighting

Hi there

I'm currently modifying the process that I wrote a few months ago so that the process returns not a single file but several files. That is, if I input 100 epochs I want my script to process the 100 epochs according to the calculation specified and return 100 epochs. I thought this would only require a simple matter of deleting some lines in my script but it looks like this could be more complicated than I first thought.

Right now the script that I wrote with the help of Francois and Raymundo takes in X number of epochs, processes them all at once and returns a single averaged output.

I would like to know where I need to change my file so that the process returns X number of epoch outputs that is the same number of X number of epoch inputs.
The process that I wrote is inspired from the example custom processing.

For Brainstorm to understand that you want to return multiple files, you only need to have the list of all the file paths returned in the cell-array OutputFiles.
You basically need to move all the lines that create a new file (bst_process('GetNewFilename'), save, db_add_data) inside the for loop. Don't forget to increment the index: use OutputFiles{i} instead of OutputFiles{1}.

Thanks for that input Francois.
I took your advice and modified the code as follows.
I included all the lines that are involved in the processing and then outputting/saving the files into the "for" loop so that it returns X number of outputs based on the X number of inputs.

It works well but there are two issues currently.
Firstly the process returns my epochs into files as shown rather than the Brainstorm's way of including all the epochs into the "+" files group. How do I change the code so that all the epochs are included in this Brainstorm fashion?
image

Secondly, when you open each processed file they seem to NOT have a unit (it should be uV) and instead the scale is usually 10^6 or 10^7. How shall I fix this??
I've modified the code several times to include things like Data10^(-6) or Data10^(-7) but then this creates strange issues with units being changed into mV (rather than micro volts) and sometimes it still did not show any units.

Any help would be greatly appreciated.
Kind Regards.

How do I change the code so that all the epochs are included in this Brainstorm fashion?

The files are grouped together under a node "trial group" only when they have the same name.
Here they have different names (e.g. WEpoch, Epoch_02...). This tag at the end is added by db_add_data.
One solution is to remove the call to db_add_data, and reload the folder after the end of the loop, using db_reload_studies.

Secondly, when you open each processed file they seem to NOT have a unit (it should be uV) and instead the scale is usually 10^6 or 10^7. How shall I fix this??

You need to fix the values that are save in the file.
All the values in Brainstorm must be in plain international units. EEG values must be saved in Volts.
Therefore all the values you save in the file must be in the range of 10^-6, instead of 10^6 as what appears to be available in your file.

Thanks Francois - this is now working nicely :slight_smile: