<div dir="ltr">Hey Arjen, hey all,<div><br></div><div>so, I used some if statements, yes, and now I really get lists of trialbegin, trialend, offset and RT as I wanted them, however at the end only one segment  (with the last infos of the lists) is created. I just don't get what is wrong. Could you have another short look? </div><div>Thanks a million</div><div>Katrin</div><div><br></div><div>







<p class=""><span class="">function</span> [trl, event] = response_trialfun(cfg);</p>
<p class=""> </p>
<p class="">% read the header information and the events from the data</p>
<p class="">hdr   = ft_read_header(cfg.dataset);</p>
<p class="">event = ft_read_event(cfg.dataset);</p>
<p class=""> </p>
<p class="">% search for "trigger" events</p>
<p class="">value  = [event(find(strcmp(<span class="">'ceck'</span>, {event.value}))).value]';</p>
<p class="">sample = [event(find(strcmp(<span class="">'ceck'</span>, {event.value}))).sample]'</p>
<p class=""> </p>
<p class="">% search for "trigger" events</p>
<p class="">value2  = [event(find(strcmp(<span class="">'resp'</span>, {event.value}))).value]';</p>
<p class="">sample2 = [event(find(strcmp(<span class="">'resp'</span>, {event.value}))).sample]'</p>
<p class=""> </p>
<p class="">% determine the number of samples before and after the trigger</p>
<p class="">pretrig  = -round(cfg.trialdef.prestim  * hdr.Fs);</p>
<p class="">posttrig =  round(cfg.trialdef.poststim * hdr.Fs);</p>
<p class=""> </p>
<p class="">trl = [];</p>
<p class="">trlbegin = [];</p>
<p class="">trlend = []</p>
<p class="">offset = [];</p>
<p class="">RT = [];</p>
<p class="">   </p>
<p class="">   i=7 %delete training trials</p>
<p class="">   j=1</p>
<p class="">   k=1</p>
<p class="">   <span class="">while</span> i <= (length(sample))</p>
<p class="">       </p>
<p class="">   <span class="">if</span> sample2(j)-sample(i)<=2500 & sample2(j)-sample(i)>=1 % find resp appearing after ceck within RT-window</p>
<p class="">   </p>
<p class="">    trlbegin (k) = sample (i) + pretrig;</p>
<p class="">    trlend (k)  = sample (i) + posttrig;       </p>
<p class="">    offset (k)  = sample (i) - sample (i) + pretrig;</p>
<p class="">    RT(k)       = sample2 (j) - sample (i);</p>
<p class="">    </p>
<p class="">    i=i+1</p>
<p class="">    j=j+1</p>
<p class="">    k=k+1</p>
<p class="">    <span class="">elseif</span> sample2(j)-sample(i)<=0</p>
<p class="">    j=j+1</p>
<p class="">    <span class="">else</span> </p>
<p class="">    i=i+1</p>
<p class="">    <span class="">end</span></p>
<p class="">   <span class="">end</span></p>
<p class=""> </p>
<p class="">    newtrl = [trlbegin trlend offset RT];</p>
<p class="">    trl    = [trl; newtrl]</p>
<p class=""> </p>
<p class=""><br></p></div></div><div class="gmail_extra"><br><div class="gmail_quote">2014-12-10 7:19 GMT+01:00 Arjen Stolk <span dir="ltr"><<a href="mailto:a.stolk8@gmail.com" target="_blank">a.stolk8@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Het katrin, you could make a couple of conditional if statements (eg creating and changing the value of a variable event1ctr). For example, conceptually:</p>
<p dir="ltr">Event1ctr = 0</p>
<p dir="ltr">Loop start</p>
<p dir="ltr">If event1 & event1ctr == 0<br>
Event1ctr = 1<br>
Elseif event1 & event1ctr<br>
Trl = ... with a zero for trlend # no event2 found<br>
Event1ctr = 0<br>
End</p>
<p dir="ltr">If event2<br>
Trl = ... # normal trial<br>
Event1ctr= 0<br>
End</p>
<p dir="ltr">Loop end</p>
<div class="gmail_quote">Op 9 dec. 2014 23:52 schreef "KatrinH Heimann" <<a href="mailto:katrinheimann@gmail.com" target="_blank">katrinheimann@gmail.com</a>> het volgende:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Hey Fieldtrippers,<div><br></div><div>I am fighting with a self defined trialfunction.</div><div>Basically I want to cut always at one event called ceck. If there is another event in the piece cut out, called resp I want to  log the distance between the two of them.</div><div>I tried</div><div><br></div><div><div>function [trl, event] = response_trialfun(cfg);</div><div><br></div><div>% read the header information and the events from the data</div><div>hdr   = ft_read_header(cfg.dataset);</div><div>event = ft_read_event(cfg.dataset);</div><div><br></div><div><br></div><div>% search for "trigger" events</div><div>value  = [event(find(strcmp('pres', {event.value}))).value]';</div><div>sample = [event(find(strcmp('pres', {event.value}))).sample]';</div><div><br></div><div>% search for "trigger" events</div><div>value2  = [event(find(strcmp('resp', {event.value}))).value]';</div><div>sample2 = [event(find(strcmp('resp', {event.value}))).sample]';</div><div><br></div><div>% determine the number of samples before and after the trigger</div><div>pretrig  = -round(cfg.trialdef.prestim  * hdr.Fs);</div><div>posttrig =  round(cfg.trialdef.poststim * hdr.Fs);</div><div><br></div><div>trl = [];</div><div>   </div><div>    trlbegin = sample + pretrig       </div><div>    trlend   = sample + posttrig       </div><div>    offset   = sample - sample + pretrig</div><div>    RT       = sample2 - sample</div><div>   </div><div>    newtrl   = [trlbegin trlend offset RT];</div><div>    trl      = [trl; newtrl];</div><div>     </div><div>end</div></div><div><br></div><div><br></div><div>But the problem is, that not always there is this second event, so length(sample1) is not equal to length (sample2). Now I would just like that every time when event 2 is missing sample 2 is just set to zero, so that the two vectors have the same length and the function is working. Is this possible?</div><div>Thanks a million</div><div>Katrin</div></div>
<br></div></div>_______________________________________________<br>
fieldtrip mailing list<br>
<a href="mailto:fieldtrip@donders.ru.nl" target="_blank">fieldtrip@donders.ru.nl</a><br>
<a href="http://mailman.science.ru.nl/mailman/listinfo/fieldtrip" target="_blank">http://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br></blockquote></div>
<br>_______________________________________________<br>
fieldtrip mailing list<br>
<a href="mailto:fieldtrip@donders.ru.nl">fieldtrip@donders.ru.nl</a><br>
<a href="http://mailman.science.ru.nl/mailman/listinfo/fieldtrip" target="_blank">http://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br></blockquote></div><br></div>