Coding for **By trial group (folder average)**

As per your suggestion I've included the block that loads all the input files into AllMat

But I can see you didn't replace all the sInputs with sInputs(iGroups(i)).
This is not going to work.

As per your suggestion I've used GetOutputStudy and changed line 132 from:

Please see how this is done in process_average.m.

These questions are related with Matlab programming, and not Brainstorm. There are beyond the scope of this forum, which is to provide help in using Brainstorm. Maybe you need to train deeper with Matlab coding before getting back to this task.

Read entirely the tutorial "How to write your own process". Then put a breakpoint at the beginning of the Run() function, start the process from the Brainstorm interface, and then execute step by step the code and inspect the variable to try and understand what this is doing.
Good luck!