All trial epochs in a single struct, from each condition—possible to do directly?

Hi everyone.

I am considering using Brainstorm for preprocessing my data and then getting an output of all epochs based on their conditions. For example here is my current status, I have my epochs ready to be exported:

image

And now I just want to export it to matlab in such a way that I get a struct which contains the conditions and epoch labels, for example, accessing a single trial would be like the following:

trial = 1 # looking at trial 1
condition = "3" # based on the trigger label from the raw data

subject001.condition.trial

I can be done manually by just exporting to MATLAB and saving the workspace, but is there a direct method for this?

Hi Darah,

Here's one way to do this. If you drag and drop a few of the trials in the process box, you should get a feel for how the files are named in Brainstorm. Right click on the process box and select Copy list to clipboard. Provided that the trials were generated in a standard way, you can probably see an obvious pattern emerge:

sFiles = {...
   'Subject01/reg_soi_ext1_ya10/data_1_trial001.mat', ...
   'Subject01/reg_soi_ext1_ya10/data_1_trial002.mat', ...
   'Subject01/reg_soi_ext1_ya10/data_1_trial003.mat'};

So the file name will be: 'Subject01/reg_soi_ext1_ya10/data_<CONDITION>_trial<TRIAL>.mat'.

You could adapt your script snipped above to look like the following:

trial = 1; # looking at trial 1
condition = '3'; # based on the trigger label from the raw data
data = load(file_fullpath(sprintf('Subject01/reg_soi_ext1_ya10/data_%s_trial%03d.mat', condition, trial)));

Does that work for you?

Best,
Martin

Hey Martin,

Thanks for the solution. So I'm assuming the distributed data output is by design (i.e separate .mat files), and after giving it more thought I kind of prefer it. I just need to work on script to read all the epochs and put them together in my specific layout.

Out of curiosity, If i want to work on the epoch data and have the option of reading both .mat and .edf files, is there any format more suitable to export/save it as? (My downstream analysis is in Julia and I'm currently writing some basic functions for reading/analyzing preprocessed data)

I've been using brainstorm all day and I'm really liking the intuitive design. I found out about it last night since I've been having continual issues with BESA (and have been looking to replace it), and I've really been digging brainstorm. Kudos for all the great work.

Thank you for the kind comments

If i want to work on the epoch data and have the option of reading both .mat and .edf files, is there any format more suitable to export/save it as? (My downstream analysis is in Julia and I'm currently writing some basic functions for reading/analyzing preprocessed data)

I'm not sure to understand what you don't like about the .mat storage and file naming/architecture produced by Brainstorm. You can load all these the .mat files directly in your Matlab scripts (with the Matlab load() function, or with some more high-level functions in Brainstorm) and in your Julia scripts.

Do not try to save back the files as EDF after processing. This file format is not suitable for floating point data, it would have to reconvert from "double" to "int16", and then back to double again when loading the file again. Not sure if this makes any sense to you, but don't do it :slight_smile:

https://neuroimage.usc.edu/brainstorm/Tutorials/Scripting

1 Like

Thank you for your reply. I really like the naming and organization of the .mat files, I was just wondering if EDF was a "better" format for me to save it—I was erroneously assuming, at the time I wrote the question, that I would have to manually export to .mat files at the end of my analysis.