<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
Hi Ruoyi,
<div class=""><br class="">
</div>
<div class="">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:</div>
<div class=""><br class="">
</div>
<div class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;">
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class="">value2 = {event.value}.';</b></i></div>
</div>
</div>
</div>
</div>
</div>
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class="">value=cell2mat(value2)</b></i></div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;">
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class="">sample = [event.sample].’</b></i></div>
<div class=""><i class=""><b class=""><br class="">
</b></i></div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div><font color="#000000" class=""><span style="caret-color: rgb(0, 0, 0);" class="">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.</span></font></div>
<div><font color="#000000" class="">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...</font></div>
<div><font color="#000000" class=""><span style="caret-color: rgb(0, 0, 0);" class=""><br class="">
</span></font></div>
<div><font color="#000000" class=""><span style="caret-color: rgb(0, 0, 0);" class="">Best wishes,</span></font></div>
<div><font color="#000000" class=""><span style="caret-color: rgb(0, 0, 0);" class="">Jan-Mathijs</span></font></div>
<div><font color="#000000" class=""><span style="caret-color: rgb(0, 0, 0);" class=""><br class="">
</span></font><br class="">
<br class="">
<blockquote type="cite" class="">
<div class="">On 6 Feb 2023, at 20:33, Ruoyi Cao via fieldtrip <<a href="mailto:fieldtrip@science.ru.nl" class="">fieldtrip@science.ru.nl</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div class=""><b class=""><font face="arial, sans-serif" class="">Hello FieldTrip community,<br class="">
</font></b></div>
<div class=""><b class=""><font face="arial, sans-serif" class="">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.</font></b></div>
<div class=""><br class="">
</div>
<div class=""><b class=""><font face="arial, sans-serif" class="">I am very confused as the outcome from my self-made function was surprisingly not the same. </font></b><b class=""><font face="arial, sans-serif" class="">Could anyone kindly give me some ideas
for why this is the case and how to fix the problem? </font></b></div>
<div class=""><b class=""><font face="arial, sans-serif" class=""><br class="">
</font></b></div>
<div class=""><b class=""><font face="arial, sans-serif" class=""><br class="">
</font></b></div>
<div class=""><b class=""><font face="arial, sans-serif" class="">Thank you so much </font></b></div>
<div class=""><b class=""><font face="arial, sans-serif" class="">Ruoyi.</font></b></div>
<div class=""><b class=""><font face="arial, sans-serif" class=""><br class="">
</font></b></div>
<div class=""><b class=""><font face="arial, sans-serif" class="">The two methods are as follows: </font></b></div>
<div class=""><b class=""><i style="" class=""><font class="">Standard code: </font></i></b></div>
<div class=""><i class=""><b class=""><font class=""><br class="">
</font></b></i></div>
<div class="">
<div class=""><i class=""><b class=""><font class="">1: </font></b></i></div>
<div class=""><i class=""><b class=""><font class="">cfg = [];</font></b></i></div>
<div class=""><i class=""><b class=""><font class="">cfg.dataset = M</font></b></i></div>
<div class=""><i class=""><b class=""><font class="">% cfg.trialdef.pre = 2.5;</font></b></i></div>
<div class=""><i class=""><b class=""><font class="">% <a href="https://urldefense.com/v3/__http://cfg.trialdef.post__;!!HJOPV4FYYWzcc1jazlU!6N0m7ApeHYcgG8eDnFRM6pJm_vl3F8FqPPpOGXDL4KV8-gkpwHh_lgp2Uz4GPQJbDOnl0_UdpSfhZCdJQuEfXasSpsBdSQ$" class="">
cfg.trialdef.post</a> = 1.5;</font></b></i></div>
<div class=""><i class=""><b class=""><font class="">cfg.trialdef.eventtype = 'STATUS';</font></b></i></div>
<div class=""><i class=""><b class=""><font class="">cfg.trialdef.prestim = 2.5; % in seconds</font></b></i></div>
<div class=""><i class=""><b class=""><font class="">cfg.trialdef.poststim = 1.5; % in seconds</font></b></i></div>
<div class=""><i class=""><b class=""><font class="">cfg.trialdef.eventvalue = 101;</font></b></i></div>
<div class=""><i class=""><b class=""><font class="">cfg_B1 = ft_definetrial(cfg);</font></b></i></div>
<div class=""><i class=""><b class=""><font class="">segbinding1= ft_redefinetrial(cfg_B1,data); </font></b></i></div>
</div>
<div class="">
<div class=""><b class=""><i class=""><font class="">Reference: </font></i></b></div>
<div class=""><a href="https://urldefense.com/v3/__https://www.fieldtriptoolbox.org/tutorial/continuous/__;!!HJOPV4FYYWzcc1jazlU!6N0m7ApeHYcgG8eDnFRM6pJm_vl3F8FqPPpOGXDL4KV8-gkpwHh_lgp2Uz4GPQJbDOnl0_UdpSfhZCdJQuEfXauX0co87g$" class=""><i class=""><b class=""><font class="">Preprocessing
- Reading continuous EEG and MEG data - FieldTrip toolbox</font></b></i></a></div>
</div>
<div class=""><br class="">
</div>
<div class=""><i class=""><b class=""><font class="">2: Self made function according to following instruction : </font></b></i></div>
<div class=""><i class=""><b class=""><font class=""><br class="">
</font></b></i></div>
<div class=""><i class=""><b class=""><font class="">function [trl, event] =location1(cfg);<br class="">
</font></b></i></div>
</div>
</div>
</div>
</div>
</div>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class=""><font class="">hdr = ft_read_header(cfg.dataset);</font></b></i></div>
</div>
</div>
</div>
</div>
</div>
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class=""><font class="">event = ft_read_event(cfg.dataset);</font></b></i></div>
</div>
</div>
</div>
</div>
</div>
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class=""><font class="">% search for "trigger" events</font></b></i></div>
</div>
</div>
</div>
</div>
</div>
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class=""><font class="">% value = [event(find(strcmp('trigger', {event.type}))).value]';</font></b></i></div>
</div>
</div>
</div>
</div>
</div>
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class=""><font class="">value2 = {event.value}.';</font></b></i></div>
</div>
</div>
</div>
</div>
</div>
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class=""><font class="">value=cell2mat(value2)</font></b></i></div>
</div>
</div>
</div>
</div>
</div>
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class=""><font class="">% sample = [event(find(strcmp('trigger', {event.type}))).sample]';</font></b></i></div>
</div>
</div>
</div>
</div>
</div>
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class=""><font class="">sample = [event.sample].'</font></b></i></div>
</div>
</div>
</div>
</div>
</div>
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class=""><font class="">% determine the number of samples before and after the trigger</font></b></i></div>
</div>
</div>
</div>
</div>
</div>
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class=""><font class="">pretrig = -round(cfg.trialdef.pre * hdr.Fs);</font></b></i></div>
</div>
</div>
</div>
</div>
</div>
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class=""><font class="">posttrig = round(<a href="https://urldefense.com/v3/__http://cfg.trialdef.post__;!!HJOPV4FYYWzcc1jazlU!6N0m7ApeHYcgG8eDnFRM6pJm_vl3F8FqPPpOGXDL4KV8-gkpwHh_lgp2Uz4GPQJbDOnl0_UdpSfhZCdJQuEfXasSpsBdSQ$" class="">cfg.trialdef.post</a>
* hdr.Fs);</font></b></i></div>
</div>
</div>
</div>
</div>
</div>
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class=""><font class="">% for each trigger except the last one</font></b></i></div>
</div>
</div>
</div>
</div>
</div>
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class=""><font class="">trl = [];</font></b></i></div>
</div>
</div>
</div>
</div>
</div>
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class=""><font class="">for j = 1:(length(value)-3)</font></b></i></div>
</div>
</div>
</div>
</div>
</div>
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class=""><font class=""> trg1 = value(j); </font></b></i></div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class="">
<div dir="ltr" class="">
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class=""><font class="">if (trg1==101);</font></b></i></div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</blockquote>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class="">
<div dir="ltr" class="">
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class=""><font class="">trlbegin = sample(j) + pretrig;</font></b></i></div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</blockquote>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class="">
<div dir="ltr" class="">
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class=""><font class="">trlend = sample(j) + posttrig;</font></b></i></div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</blockquote>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class="">
<div dir="ltr" class="">
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class=""><font class="">offset = pretrig;</font></b></i></div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</blockquote>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class="">
<div dir="ltr" class="">
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class=""><font class="">newtrl = [trlbegin trlend offset ];;</font></b></i></div>
<div class=""><i class=""><b class=""><font class=""> trl = [trl; newtrl] </font></b></i></div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</blockquote>
<div dir="ltr" class="">
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><i class=""><b class=""><font class="">end</font></b></i></div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div class=""><i class=""><b class=""><font class="">end</font></b></i></div>
<div class=""><i class=""><b class=""><font class=""><br class="">
</font></b></i></div>
<div class=""><i class=""><b class=""><font class="">This function was run with : </font></b></i></div>
<div class="">
<div class=""><i class=""><b class=""><font class="">cfg = [];</font></b></i></div>
<div class=""><i class=""><b class=""><font class="">cfg.dataset = M</font></b></i></div>
<div class=""><i class=""><b class=""><font class="">cfg.trialdef.pre = 2.5;</font></b></i></div>
<div class=""><i class=""><b class=""><font class=""><a href="https://urldefense.com/v3/__http://cfg.trialdef.post__;!!HJOPV4FYYWzcc1jazlU!6N0m7ApeHYcgG8eDnFRM6pJm_vl3F8FqPPpOGXDL4KV8-gkpwHh_lgp2Uz4GPQJbDOnl0_UdpSfhZCdJQuEfXasSpsBdSQ$" class="">cfg.trialdef.post</a>
= 1.5;</font></b></i></div>
<div class=""><i class=""><b class=""><font class="">cfg.trialfun = 'location1';</font></b></i></div>
<div class=""><i class=""><b class=""><font class="">cfg_B1 = ft_definetrial(cfg);</font></b></i></div>
<div class=""><i class=""><b class=""><font class="">segbinding1= ft_redefinetrial(cfg_B1,data);</font></b></i></div>
</div>
<div class=""><i class=""><b class=""><font class="">References </font></b></i></div>
<div class=""><i class=""><b class=""><font class=""><a href="https://urldefense.com/v3/__https://www.fieldtriptoolbox.org/example/making_your_own_trialfun_for_conditional_trial_definition/__;!!HJOPV4FYYWzcc1jazlU!6N0m7ApeHYcgG8eDnFRM6pJm_vl3F8FqPPpOGXDL4KV8-gkpwHh_lgp2Uz4GPQJbDOnl0_UdpSfhZCdJQuEfXatuNjCdqQ$" class="">Making
your own trialfun for conditional trial definition - FieldTrip toolbox</a><br class="">
</font></b></i></div>
<div class=""><b class=""><font face="comic sans ms, sans-serif" class=""><i class=""><br class="">
</i></font></b></div>
<div class=""><b class=""><font face="arial narrow, sans-serif" class=""><i class="">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. </i></font></b></div>
<div class=""><i class=""><b class=""><font class=""><br class="">
</font></b></i></div>
<div class=""><i class=""><b class=""><font class=""><span id="cid:ii_ldt71xeb2"><image.png></span></font></b></i><br class="">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
_______________________________________________<br class="">
fieldtrip mailing list<br class="">
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" class="">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br class="">
https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!_MVGSW6yRgkWvGt4xy4cmB_vlZyD-pBdlbVepuQMeFvwrOtYJgIGHAAo0UbHZSnMQFmpY44JpbC233m34wdGVGr04n82eQoxcxg4aA$
<br class="">
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>