[FieldTrip] ft_definetrial Error on Field trip

Vanessa Oluwato Ayo-Jibunoh vayojibunoh at gradcenter.cuny.edu
Thu Jun 20 00:28:33 CEST 2024


Good evening,

Hope your day is going well.

My name is Vanessa Ayo- Jibunoh and I am working in the Perception Lab at the CUNY Graduate Center in New York city on Ensemble Perception. I am currently analyzing data for this project, where we recorded using EEG.

I'm reaching out because I keep getting this error message "Error using ft_definetrial (line 209)
no trials were defined, see FT_DEFINETRIAL for help" when I try to define my trials.

I'm working with a .set datafile from EEGlab and I'm trying to separate my EEG data by trials using the ft_definetrail function.

Provided below are the cfg details I'm working with.

cfg =

  struct with fields:

    datafile: 'Acquisition 09.set'
    trialfun: 'trialfun_orientation_trigger'
    trialdef: [1×1 struct]


And, as it is an EEG datafile, this is the event structure.

event =

  1×1798 struct array with fields:

    type
    value
    sample
    offset
    duration
    urevent


I have written the code for the "trialfun" function that precedes the ft_definetrialfunction and it seems to be written just fine and according to the code provided by this link on the fieldtrip website itself  "Making your own trialfun for conditional trial definition - FieldTrip toolbox<https://www.fieldtriptoolbox.org/example/trialfun/>" . This is the code;

function [trl, event] = trialfun_orientation_trigger(cfg);
cfg.dataset = 'Acquisition 09.set'
cfg.trialdef.prestim = 0.5
cfg.trialdef.poststim = 1
hdr = ft_read_header(cfg.dataset)
event = ft_read_event (cfg.dataset)
value = [event(find(strcmp('trigger', {event.type}))).value]'
sample = [event(find(strcmp('trigger', {event.type}))).sample]'
pretrig = -round(cfg.trialdef.prestim * hdr.Fs)
posttrig = round(cfg.trialdef.poststim * hdr.Fs)
trl = []
for j = 1:(length(value)-1)
trg1 = value(j);
trg2 = value (j+2);
if trg1==10 && trg2==50
trlbegin = sample(j) + pretrig;
trlend = sample(j) + posttrig;
offset = pretrig;
newtrl = [trlbegin trlend offset];
trl = [trl; newtrl];
end
end
end
However, when I plug this function into another code to define the trial, it gives me the error "Error using ft_definetrial (line 209) no trials were defined, see FT_DEFINETRIAL for help".

I will also provide the final code that is giving me a problem below
cfg = []
cfg.datafile = 'Acquisition 09.set' ;
cfg.trialfun = 'trialfun_orientation_trigger';
cfg.trialdef.eventtype = 'trigger';
cfg.trialdef.eventvalue = [0 10 20];
cfg.trialdef.prestim = .5;
cfg.trialdef.poststim = 1;
ft_definetrial(cfg);
I'm not sure if it is a syntax error or I would have to write another code separately to define the 'trigger' in the event type as well to get the ft_definetrial function to work. I would like assistance from someone who is better experienced with this please.

Thank you,
God bless you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20240619/64597dda/attachment.htm>


More information about the fieldtrip mailing list