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