Script to duplicate and merge event codes

Good afternoon and Happy Easter,

I am quite new to Brainstorm and MatLab syntax in general. However, I am attempting to systematically take a subjects' data and create new event codes out of combinations of existing ones. Say, for instance, I wanted to examine whether the stimuli was presented on the top of the screen or the bottom, for top it would be events (31, 33, 35, 37, 39, 41, 43, and 45). However, manually doing this for all 70 subjects is tetious and subject to error.
So I tried scripting it using your tutorial @ https://neuroimage.usc.edu/brainstorm/Tutorials/Scripting#Example:_Editing_events

It was very helpful with setting up the skeleton, however, it did not allow for multiple events.

Currently I have:

"

% Find the index of the event category "button"

iEvtCorr = find(strcmpi({sRaw.F.events.label}, or('31,'33', '35', '37', '39', 41', '43', '45')));

% Copy the event category "button" to a new category

iEvtNew = length(sRaw.F.events) + 1;

sRaw.F.events(iEvtNew) = sRaw.F.events(iEvtCorr);

% Rename the new event to "button_offset"

sRaw.F.events(iEvtNew).label = 'Correct3';

nTimes = size(sRaw.F.events(iEvtNew).times, 2);

sRaw.F.events(iEvtNew).epochs = ones(1, nTimes);

sRaw.F.events(iEvtNew).channels = cell(1, nTimes);

sRaw.F.events(iEvtNew).notes = cell(1, nTimes);

% Change the event color to yellow (red=1, green=1, blue=0)

sRaw.F.events(iEvtNew).color = [1 1 0];

% Update the sRaw structure to the RawFile file (the last parameter appends to the existing struct)

bst_save(file_fullpath(RawFile), sRaw, 'v6', 1);

"

This is what I have.

The bolded section is where I tripped up the program. It keeps assigning the error:

"

Unable to perform assignment because the left and right sides have a different number of

elements.

Error in script_new (line 14)

sRaw.F.events(iEvtNew) = sRaw.F.events(iEvtCorr);

"

Any advice would be well received.

Thanks!

You have two cell arrays of strings (read a few tutorials about cell arrays in Matlab first):

{sRaw.F.events.label}
{'31,'33', '35', '37', '39', 41', '43', '45'}

To test if each of the elements in the first list is part of the second list, use something like to get a list of event indices:

iEvtTop = find(ismember({sRaw.F.events.label}, {'31,'33', '35', '37', '39', 41', '43', '45'}));

Grouping all the occurrences of all these events could look like something like this:

[sRaw.F.events(iEvtTop ).times];

After that, ideally you need to sort all the occurrences by time, to get a correctly defined Brainstorm structure, and then apply the same sorting to all the other arrays (epochs, channels, notes...) if they vary.

All this will probably require you teach yourself some more Matlab programming first. This forum is dedicated to providing help and support specifically for the Brainstorm software. We can help you with some specific details you are stuck with, but unfortunately we won't be able to guide you through all the steps of the development of your personal Matlab scripts.

Welcome and enjoy the training!