[FieldTrip] Segmenting data with ft_trialfun_general and with self-made function.

Ruoyi Cao ruoyi.cao at mail.huji.ac.il
Mon Feb 6 20:33:51 CET 2023


*Hello FieldTrip community,*
*I segmented data by triggers after artifact correction on continuous data
, where all deleted parts were replaced with NaN. Then this data mat was
segmented with ft_trialfun_general and with a self made function as
follows. The NaN value was later deleted after the output was time
locked to the trigger.*

*I am very confused as the outcome from my self-made function was
surprisingly not the same. **Could anyone kindly give me some ideas for why
this is the case and how to fix the problem? *


*Thank you so much *
*Ruoyi.*

*The two methods are as follows: *
*Standard code: *

*1: *
*cfg = [];*
*cfg.dataset             = M*
*% cfg.trialdef.pre    =  2.5;*
*% cfg.trialdef.post <https://urldefense.com/v3/__http://cfg.trialdef.post__;!!HJOPV4FYYWzcc1jazlU!6N0m7ApeHYcgG8eDnFRM6pJm_vl3F8FqPPpOGXDL4KV8-gkpwHh_lgp2Uz4GPQJbDOnl0_UdpSfhZCdJQuEfXasSpsBdSQ$ >   =  1.5;*
*cfg.trialdef.eventtype      = 'STATUS';*
*cfg.trialdef.prestim        = 2.5; % in seconds*
*cfg.trialdef.poststim       = 1.5; % in seconds*
*cfg.trialdef.eventvalue = 101;*
*cfg_B1 = ft_definetrial(cfg);*
*segbinding1= ft_redefinetrial(cfg_B1,data); *
*Reference: *
*Preprocessing - Reading continuous EEG and MEG data - FieldTrip toolbox*
<https://urldefense.com/v3/__https://www.fieldtriptoolbox.org/tutorial/continuous/__;!!HJOPV4FYYWzcc1jazlU!6N0m7ApeHYcgG8eDnFRM6pJm_vl3F8FqPPpOGXDL4KV8-gkpwHh_lgp2Uz4GPQJbDOnl0_UdpSfhZCdJQuEfXauX0co87g$ >

*2:  Self made function according to following instruction : *


*function [trl, event] =location1(cfg);*

*hdr   = ft_read_header(cfg.dataset);*
*event = ft_read_event(cfg.dataset);*
*% search for "trigger" events*
*% value  = [event(find(strcmp('trigger', {event.type}))).value]';*
*value2 = {event.value}.';*
*value=cell2mat(value2)*
*% sample = [event(find(strcmp('trigger', {event.type}))).sample]';*
*sample = [event.sample].'*
*% determine the number of samples before and after the trigger*
*pretrig  = -round(cfg.trialdef.pre  * hdr.Fs);*
*posttrig =  round(cfg.trialdef.post <https://urldefense.com/v3/__http://cfg.trialdef.post__;!!HJOPV4FYYWzcc1jazlU!6N0m7ApeHYcgG8eDnFRM6pJm_vl3F8FqPPpOGXDL4KV8-gkpwHh_lgp2Uz4GPQJbDOnl0_UdpSfhZCdJQuEfXasSpsBdSQ$ > * hdr.Fs);*
*% for each trigger except the last one*
*trl = [];*
*for j = 1:(length(value)-3)*
*           trg1 = value(j); *

*if (trg1==101);*

*trlbegin = sample(j) + pretrig;*

*trlend   = sample(j) + posttrig;*

*offset   = pretrig;*

*newtrl   = [trlbegin trlend  offset ];;*
* trl      = [trl; newtrl]   *

*end*

*end*

*This function was run with : *
*cfg = [];*
*cfg.dataset             = M*
*cfg.trialdef.pre    =  2.5;*
*cfg.trialdef.post <https://urldefense.com/v3/__http://cfg.trialdef.post__;!!HJOPV4FYYWzcc1jazlU!6N0m7ApeHYcgG8eDnFRM6pJm_vl3F8FqPPpOGXDL4KV8-gkpwHh_lgp2Uz4GPQJbDOnl0_UdpSfhZCdJQuEfXasSpsBdSQ$ >   =  1.5;*
*cfg.trialfun = 'location1';*
*cfg_B1 = ft_definetrial(cfg);*
*segbinding1= ft_redefinetrial(cfg_B1,data);*
*References *

*Making your own trialfun for conditional trial definition - FieldTrip
toolbox
<https://urldefense.com/v3/__https://www.fieldtriptoolbox.org/example/making_your_own_trialfun_for_conditional_trial_definition/__;!!HJOPV4FYYWzcc1jazlU!6N0m7ApeHYcgG8eDnFRM6pJm_vl3F8FqPPpOGXDL4KV8-gkpwHh_lgp2Uz4GPQJbDOnl0_UdpSfhZCdJQuEfXatuNjCdqQ$ >*

*The following excels shows two different trial definitions given by these
two methods. The highlighted value is the differences between the beginning
of each segment for each detected trial between two methods. *

*[image: image.png]*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20230206/2156ba8a/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 60150 bytes
Desc: not available
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20230206/2156ba8a/attachment.png>


More information about the fieldtrip mailing list