[FieldTrip] How to select trials based on their timing

Stephen Politzer-Ahles stephen.politzer-ahles at ling-phil.ox.ac.uk
Thu Jan 28 12:10:16 CET 2016


Hi Hayes,

This isn't really about Fieldtrip specifically, but is a MATLAB programming
issue; that is to say, the solution isn't a special Fieldtrip function or
anything like that, just basic MATLAB coding. (There might be a
Fieldtrip-internal solution, like there is in ERPLAB for relatively complex
trial selection, but I'm not aware of it.)

All you really need to do is rewrite the trigger numbers so they
distinguish the kinds of triggers you actually need. For example, rather
than all trials of a given condition being coded as 30, you might want
correct trials in that condition to be 31 and incorrect trials 32; the same
logic also goes for recoding the trials based on whether or not there was a
20 nearby. All this information about trial timing is available in the
'cfg.trl' matrix that is created after you run ft_definetrial (see
http://www.fieldtriptoolbox.org/reference/definetrial for details about how
this matrix is organized). So all you need to do is write a FOR loop that
iterates through each row of the trl matrix, and for each row checks (using
an IF statement) whether that row meets the various conditions you
outlined, and rewrites that row's trigger code if it meets those
conditions. Then you can pull out a list of which trials you want (this is
doable with basic MATLAB code, e.g., find(cfg.trl(:,3)==31) gives you a
list of the row numbers of every trial with a code of 31) and use that list
with ft_preprocessing to process just the trials you want.

Best,
Steve



---
Stephen Politzer-Ahles
University of Oxford
Language and Brain Lab
Faculty of Linguistics, Phonetics & Philology
http://users.ox.ac.uk/~cpgl0080/


> Message: 3
> Date: Wed, 27 Jan 2016 20:57:20 -0600
> From: Hayes Brenner <hayes.brenner at gmail.com>
> To: fieldtrip at science.ru.nl
> Subject: [FieldTrip] How to select trials based on their timing
> Message-ID:
>         <
> CAB--YMYoCGP7KKCW-a7DwP2iZgyCVO-D_SJh1dmjUP79NtcLow at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Hello everyone! I'm fairly new to Fieldtrip, so I apologize if this
> question seems trivial, but I've been stuck for a while and I would greatly
> appreciate everyone's help.
>
> I have a set of data that I'm working on to get a better sense of how to
> process EEG data. I'm having trouble with this part when given these
> instructions:
>
> "let's only grab trials in which a '30' also appeared along side the '20'.
> [These labels are a part of cfg.trialdef.eventtype]. This '30' event code
> denotes a certain kind of trial in the experiment in which only the colored
> square was presented. The '30' event code should onset at the same time or
> within just a few milliseconds of the onset of the '20'. Third, let's also
> only grab trials in which subjects correctly responded with a button press
> to the stimulus (i.e., the colored square). To do this, you'll need to make
> sure there is a '90' following the '20'. The button press (or event code
> '90') should appear within 1000 ms of the onset of the '20'.
>
> My question is: how can I designate my code so that I can have a data set
> that meets the following conditions? I know I should use an 'if' or 'for'
> but I'm not sure how to write it exactly. Any advice? I've included my code
> as is without including the file upload. As of now, I created 3 data sets,
> each one with the required markers (20, 30, and 90).
>
> ft_defaults;
> cfg = [];
> cfg.trialdef.eventtype = '?';
> ft_definetrial(cfg);
> cfg.trialdef.eventtype = 'Stim';
> cfg.trialdef.prestim = 0.2;
> cfg.trialdef.poststim = .8;
> cfg.trialdef.eventvalue = '20';
> cfg1=ft_definetrial(cfg);
> cfg.trialdef.eventvalue = '30';
> cfg2=ft_definetrial(cfg);
> cfg.trialdef.eventvalue = '90';
> cfg3=ft_definetrial(cfg);
> cfg.lpfilter='yes';
> cfg.lpfreq = 30;
> cfg.reref         = 'yes';
> cfg.implicitref   = 'REF';
> cfg.refchannel    = {'LM' 'REF'};
> trialdata1 = ft_preprocessing(cfg1);
> trialdata2 = ft_preprocessing(cfg2);
> trialdata3 = ft_preprocessing(cfg3);
>
> Thank you all so much!
>
> Hayes Brenner
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20160127/b0726da2/attachment-0001.html
> >
>
> ------------------------------
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20160128/e820e2af/attachment-0002.html>


More information about the fieldtrip mailing list