[FieldTrip] ft_definetrial
Schoffelen, J.M. (Jan Mathijs)
jan.schoffelen at donders.ru.nl
Fri Jun 19 08:52:26 CEST 2020
Dear Hannah,
From your error, it seems that you called ft_REdefinetrial, rather than ft_definetrial, I am not sure whether that was intended.
The way forward would be (in your case)
cfg = ft_definetrial(cfg);
% this yields a cfg.trl matrix that defines epochs - from - marker1 - to - marker2
Then, you can use ft_preprocessing(cfg) to load in the epoched data, followed by a call to ft_redefinetrial to cut the epochs into 2 second snippets.
Alternatively, you can write a fancy ’trialfun’ that also incorporates the cutting into epochs of desired length (+desired overlap). Perhaps you can have a look at Appendix 2 of this tutorial: http://www.fieldtriptoolbox.org/tutorial/coherence/, which gives an example of such a trialfun.
Best wishes,
Jan-Mathijs
On 19 Jun 2020, at 05:31, Hannah Anderson <handerson at usc.edu.au<mailto:handerson at usc.edu.au>> wrote:
Dear FieldTrip community
I am attempting to define a trial based on a start and end marker, and then cut the trial into 2 second segments with 0.5% overlap.
Marker Segmentation
cfg = [];
cfg.dataset = d(data).name;
cfg.continuous = 'yes';
cfg.trialfun = 'trial_fun_startend'; %trial_function for marker segmentation
cfg.trialdef.prestim = 0.2; %in seconds
cfg.trialdef.poststim = 0; %in seconds
cfg.trialdef.ntrials = inf;
cfg = ft_definetrial(cfg); % define trials
I created a trial fun which is successful in creating a trial from start marker to end marker but I get an error I get an error;
-Index in position 2 exceeds array bounds (must not exceed 2)
Error in ft_redefinetrial (line 267)
offset = newtrl(:,3);
when I try and then segment the trial into 2 second trials with overlap.
This is my trialfun:
function [trl, event] = trial_fun_startend(cfg);
hdr = ft_read_header(cfg.dataset);
event = ft_read_event(cfg.dataset);
detectflank = 'up';
value = [event(find(strcmp('STATUS', {event.type}))).value]';
sample = [event(find(strcmp('STATUS', {event.type}))).sample]';
trl = [];
sel = find(strcmp({event.type}, 'STATUS'));
event = event(sel)
begsample = event(1, 2);
endsample = event(1, 3);
offset = newtrl(:,3);
trl = [begsample endsample];
I am not sure what else I can try as the other define trial options segment the data into two trials (one for each trigger) and I need it to be one dataset starting at trigger 1 and ending at trigger 2. If anyone could offer some advice/assistance it would be greatly appreciated.
Kind regards,
Hannah
University of the Sunshine Coast l CRICOS 01595D
_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20200619/7136ae0f/attachment.htm>
More information about the fieldtrip
mailing list