<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">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 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>_______________________________________________<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>