[FieldTrip] Segmenting data with ft_trialfun_general and with self-made function.
Ruoyi Cao
ruoyi.cao at mail.huji.ac.il
Tue Feb 7 00:32:28 CET 2023
Hi Jan-Mathijs:
Thank you so much for your fast response ! This is exactly the problem.
There is one empty event in the bdf file.
Best wishes,
Ruoyi
On Mon, Feb 6, 2023 at 10:35 PM Schoffelen, J.M. (Jan Mathijs) via
fieldtrip <fieldtrip at science.ru.nl> wrote:
> Hi Ruoyi,
>
> I don’t know about the specific file format you are working with, but -
> occasionally in some file formats - some events may have an empty value. As
> a consequence, the code that you used in your selfmade function may not
> have been absolutely robust. Specifically, the three lines:
>
> *value2 = {event.value}.';*
> *value=cell2mat(value2)*
>
> *sample = [event.sample].’*
>
> lead to two vectors (value and sample) that are assumed to relate to each
> other one-by-one, meaning that element -i- in one of the vectors
> corresponds to element -i- in the other vector.
> I would first check if this is really the case in your data. If not, I
> think that this explains the discrepancy you report, and would be
> indicative that you may need to change your own code a bit, in order to
> obtain the expected behavior. You could quickly check this: a = {1 2 [] 3};
> b = cell2mat(a); As you will see, ‘a’ has 4 elements, ‘b’ only 3...
>
> Best wishes,
> Jan-Mathijs
>
>
>
> On 6 Feb 2023, at 20:33, Ruoyi Cao via fieldtrip <fieldtrip at science.ru.nl>
> wrote:
>
>
> *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.png>*
> _______________________________________________
> fieldtrip mailing list
> https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>
> https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!_MVGSW6yRgkWvGt4xy4cmB_vlZyD-pBdlbVepuQMeFvwrOtYJgIGHAAo0UbHZSnMQFmpY44JpbC233m34wdGVGr04n82eQoxcxg4aA$
>
>
> _______________________________________________
> fieldtrip mailing list
> https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
> https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!_CbrzMjS8UupcSJQiDc0f0JqnvhhEthw70my2Lkjee7fPGr_4Ouk3t3z6lBeS9O6Sk3kK714IbE5ro_wW6-Z4jR9SKmjcA$
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20230207/7e0628b4/attachment.htm>
More information about the fieldtrip
mailing list