Note that this reference documentation is identical to the help that is displayed in Matlab when you type “help ft_definetrial”.
FT_DEFINETRIAL defines the trials, i.e. the pieces of data that will be read
in for preprocessing. Trials are defined by their begin and end sample
in the data file and each trial has an offset that defines where the
relative t=0 point (usually the point of the trigger) is for that trial.
Use as
[cfg] = ft_definetrial(cfg)
where the configuration structure should contain either
cfg.trialdef = structure with details of trial definition, see below
cfg.trialfun = function name, see below
A call to FT_DEFINETRIAL results in the trial definition "trl" being added
to the output configuration structure. The trials are defined according
to the triggers, trials or other events in the data, or from a
user-specified Matlab function which returns "trl".
The trial definition "trl" is an Nx3 matrix, N is the number of trials.
The first column contains the sample-indices of the begin of each trial
relative to the begin of the raw data, the second column contains the
sample-indices of the end of each trial, and the third column contains
the offset of the trigger with respect to the trial. An offset of 0
means that the first sample of the trial corresponds to the trigger. A
positive offset indicates that the first sample is later than the trigger,
a negative offset indicates that the trial begins before the trigger.
Simple trial definitions (e.g. based on a trigger alone) are supported by
FT_DEFINETRIAL itself. For this, the general and data format independent way
of handling trials is by relying on the FT_READ_EVENT function to
collect all event information (such as triggers) from your dataset and
select trials based on those events. This is implemented in FT_DEFINETRIAL as
cfg.trialdef.eventtype = 'string'
cfg.trialdef.eventvalue = number, string or list with numbers or strings
cfg.trialdef.prestim = number, latency in seconds (optional)
cfg.trialdef.poststim = number, latency in seconds (optional)
If you specify cfg.trialdef.eventtype = '?' a list with the events in your
data file will be displayed on screen.
However, there are also many other complex ways in which you can define
data pieces of interest, for example based on a conditional sequence of
events (e.g. stimulus trigger followed by a correct response). For those
cases, a general mechanism has been implemented through which you can
supply your own trial-defining function, the 'trialfun'.
This 'trialfun' is a string containing the name of a function that you
have to write yourself. The function should take the cfg-structure as
input and should give a Nx3 matrix in the same format as "trl" as the
output. You can add extra custom fields to the configuration structure to
pass as arguments to your own trialfun. Furthermore, inside the trialfun
you can use the FT_READ_EVENT function to get the event information
from your data file.
See also FT_PREPROCESSING, FT_READ_HEADER, FT_READ_DATA, FT_READ_EVENT