Exporting trial data into a single matrix while excluding bad trials

Hi there,

I was wondering if there was a good way of exporting preprocessed trial data into a singe matrix while also excluding bad trials (in a single .mat file). In short, the preprocessing, trial rejection, and artifact detection capabilities of Brainstorm are very useful for my lab doing rodent ephys, though there are many analyses and such that we would like to perform that Brainstorm does not yet offer.

It would be a ideal if we could load our data from the .pl2 files (already works perfectly), preprocess and clean the data (also works perfectly), then export the data for use in Matlab (not yet implemented?).

I see that Brainstorm currently contains each trial data in a separate .m file with a [signal] x [time] matrix, so it shouldn't be too difficult to combine these into a single [trial] x [signal] x [time] matrix. I'm comfortable writing a script for this but am wondering if there is an easier solution or if there are any example scripts around this or a similar issue that anyone could provide.

Thanks,
Michael Totty

Michael,
I modified a process to create ERP-images that I think does what you need. I added an option so that instead of sorting trials, they are organized by trial count. If you add the attached process to your ".brainstorm" folder, it will appear under CPL>Visualization in the process dialog. When you run the process, just use "ALL" as the Sorting Event Label (see image below) and make sure the "External Metadata" fields are empty. This process will add a single matrix of trial data (excluding bad trials) to your protocol. This matrix is easily exported to the matlab workspace.

process_ERPimage.m (10.2 KB)

1 Like

Hi pd,

This works perfectly, thanks so much!

For learning how to manipulate Brainstorm data structures and writing your own scripts and processes, you can refer to the following tutorials:

The last example in the latter shows how to load multiple trials into a large matrix:
https://neuroimage.usc.edu/brainstorm/Tutorials/TutUserProcess#Examples-1