<div dir="ltr">For a more simple check, when I try to read the events without the trialfun ( so it uses ft_trialfun_general by default) I get the original event values:<div><br></div><div> >> cfg = [];<br></div><div>>> cfg.dataset = '27CW1.RAW';</div><div>>> cfg.trialdef.eventtype = '?';</div><div>>> cfg=ft_definetrial(cfg);</div><div><br></div><div>Warning: no trialfun was specified, using ft_trialfun_general </div><div>> In ft_definetrial at 135 </div><div>evaluating trialfunction 'ft_trialfun_general'</div><div>reading the events from '27CW1.RAW'</div><div>the following events were found in the datafile</div><div>event type: 'trigger' with event values: 'DIN1' 'DIN2' 'DIN4' 'DIN8' </div><div>no trials have been defined yet, see FT_DEFINETRIAL for further help</div><div>found 750 events</div><div>created 0 trials</div><div>the call to "ft_definetrial" took 4 seconds</div><div><br></div><div>Then I try to use the trialfun, I get the same error</div><div><br></div><div><div>>> cfg = [];</div><div>>> cfg.dataset = '27CW1.RAW';</div><div>>> cfg.trialfun = 'trialfun_bit2dec';</div><div>>> cfg.trialdef.eventtype = '?';</div><div>>> cfg=ft_definetrial(cfg);</div><div>evaluating trialfunction 'trialfun_bit2dec'</div><div><br></div><div>Attempted to access trl(:,1); index out of bounds because size(trl)=[0,0].</div><div><br></div><div>Error in trialfun_bit2dec (line 66)</div><div>idx = any(diff(trl(:,1),1,1),2);</div><div><br></div><div>Error in ft_definetrial (line 169)</div><div> trl = feval(cfg.trialfun, cfg);</div></div><div><br></div><div>So there is something the trialfun_bit2dec does that events cannot be read anymore.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 29, 2014 at 9:01 PM, Arjen Stolk <span dir="ltr"><<a href="mailto:a.stolk8@gmail.com" target="_blank">a.stolk8@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Hi Ana Laura,<br><br></div>Your 'trl' is empty, which it shouldn't be. So anytime you try to index an element in it, it will throw an error. <br><br>Can you check what 'event.values' you find in your dataset? And compare those with any of the ones falling under the switch case statement? One way to do this, is to put a debug marker (red dot) at the 'end' of the first for-loop (judging from the wiki). Then check the value of event(i).value, and click the continue button to move on to the next. An alternative way is to put a debug marker after event = ft_read_event and to instantly check all values of event with "[event(:).value]". <br><br></div><div>Goodluck,<br>Arjen<br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">2014-09-30 6:20 GMT+02:00 Ana Laura Diez Martini <span dir="ltr"><<a href="mailto:diezmartini@gmail.com" target="_blank">diezmartini@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">This is my attempt of adapting the code for the new Fieldtrip<div><br></div><div><div> % TRIAL DEFINITION</div><div><br></div><div> cfg=[];</div><div> cfg.dataset = 'myfile';</div><div><br></div><div> hdr = ft_read_header( 'myfile');</div><div> dat = ft_read_data('myfile');</div><div> cfg.trialfun = 'trialfun_bit2dec';</div><span><div> cfg.trialdef.eventtype = 'STATUS';</div><div> cfg.trialdef.eventvalue = cgrmrk; % stimulus triggers</div><div> cfg.trialdef.prestim = 0.2;</div></span><div> cfg.trialdef.poststim = 1; </div><span><div><br></div><div> cfg.reref = 'yes';</div><div> cfg.refchannel = ['all'];<span style="white-space:pre-wrap"> </span> </div></span><div> cfg = ft_definetrial(cfg);</div></div><div><br></div><div>again the error is:</div><div><br></div><div><span><div>Attempted to access trl(:,1); index out of bounds because size(trl)=[0,0].</div><div><br></div><div>Error in trialfun_bit2dec (line 66)</div><div>idx = any(diff(trl(:,1),1,1),2);</div><div><br></div><div>Error in ft_definetrial (line 169)</div><div> trl = feval(cfg.trialfun, cfg);</div><div><br></div></span><div>Error in process_ERP_1_fieldtrip (line 106)</div><div> cfg = ft_definetrial(cfg);</div></div><div><br></div><div><br></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 29, 2014 at 12:11 PM, Ana Laura Diez Martini <span dir="ltr"><<a href="mailto:diezmartini@gmail.com" target="_blank">diezmartini@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Dear Arjen and Nietzsche, <div><br></div><div>I tried debugging with <span style="color:rgb(0,0,0);font-family:Consolas,'Andale Mono',Menlo,Monaco,monospace;font-size:12px;text-align:justify;white-space:pre-wrap;background-color:rgb(247,249,250)">dbstop if error and </span><span style="color:rgb(0,0,0);font-family:Consolas,'Andale Mono',Menlo,Monaco,monospace;font-size:12px;text-align:justify;white-space:pre-wrap;background-color:rgb(247,249,250)">cfg.debug = 'saveonerror' and matlab points to:</span></div><div><br></div><div><div>% discard the repeated values</div><div>idx = any(diff(trl(:,1),1,1),2);</div><div>trl = trl(idx,:);</div></div><div><br></div><div>It does seem it is not reading the events. When I read them with the raw data, they seem to be there, with the DIN prefix. Any idea?</div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 29, 2014 at 8:57 AM, Arjen Stolk <span dir="ltr"><<a href="mailto:a.stolk8@gmail.com" target="_blank">a.stolk8@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hey Ana Laura,<br><br></div><div>Seems from the error message you're getting <br><span><br>"Attempted to access trl(:,1); index out of bounds because size(trl)=[0,0]."<br><br></span></div><div>that none of the triggers were found in your event data. You might wanna check why this is happening, by debugging 'trialfun_bit2dec' on your input.<br><br></div><div>Best,<br>Arjen<br></div><div><br><br></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">2014-09-29 19:00 GMT+02:00 Ana Laura Diez Martini <span dir="ltr"><<a href="mailto:diezmartini@gmail.com" target="_blank">diezmartini@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thank you again Nietzsche!! <div><br></div><div>Yes, I was referring to trialfun_bit2dec. I followed your advice and I changed definetrial to ft_definetrial and I confirm the function was added to my paths. After doing this, the error I get is:</div><div><br></div><div><div>Attempted to access trl(:,1); index out of bounds because size(trl)=[0,0].</div><div><br></div><div>Error in trialfun_bit2dec (line 66)</div><div>idx = any(diff(trl(:,1),1,1),2);</div><div><br></div><div>Error in ft_definetrial (line 169)</div><div> trl = feval(cfg.trialfun, cfg);</div><div><br></div><div>Error in process_ERP_1_fieldtrip (line 95)</div><div> cfg = ft_definetrial(cfg);</div></div><div><br></div><div>This is again the trial definition part in which I think I added what I think are useless lines but I was just trying to make it run it.</div><div><br></div><div><div> % TRIAL DEFINITION</div><div> cfg=[];</div><div> cfg.filename = ['myfolders/subject.RAW']; </div><div> cfg.headerfile = ['myfolders/subject.RAW']; </div><div> cfg.dataset = ['myfolders/subject.RAW'];</div><div> cfg.trialfun = 'trialfun_bit2dec'; %% trialfun definition</div><div> cfg.trialdef.eventtype = 'STATUS';</div><div> cfg.trialdef.eventvalue = cgrmrk; % stimulus triggers</div><div> cfg.trialdef.prestim = 0.2; % latency in seconds</div><div> cfg.trialdef.poststim = 1; % latency in seconds</div><div> cfg = ft_definetrial(cfg);</div><div><br></div><div> trl = cfg.trl;</div><div> cfg=[];</div><div> cfg.dataset = ['myfolders/subject.RAW']; </div><span><div> cfg.trl = trl;</div><div> cfg.reref = 'yes';</div><div> cfg.refchannel = ['all'];<span style="white-space:pre-wrap"> </span></div></span></div><div><span style="white-space:pre-wrap"><br></span></div><div><span style="white-space:pre-wrap">Unfortunately using this function is crucial to my analysis because I would like to use only Fieldtrip to analyse all my data. Thank you for taking all this time. </span></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Sep 28, 2014 at 10:53 PM, Lam, Nietzsche <span dir="ltr"><<a href="mailto:n.lam@fcdonders.ru.nl" target="_blank">n.lam@fcdonders.ru.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi again Ana Laura,<br>
<br>
One other thing that I thought of was to make sure that the function "trialfun_bit2dec" is added to your paths in matlab, so that ft_definetrial can find this function.<br>
<br>
By updating your fieldtrip to the most recent version "trialfun_bit2dec" is *not* included. So you'll need to store that as a separate .m file in a location that can be accessed by the paths set in matlab.<br>
<span><br>
Nietzsche<br>
<br>
----- Original Message -----<br>
> From: "Ana Laura Diez Martini" <<a href="mailto:diezmartini@gmail.com" target="_blank">diezmartini@gmail.com</a>><br>
> To: "FieldTrip discussion list" <<a href="mailto:fieldtrip@science.ru.nl" target="_blank">fieldtrip@science.ru.nl</a>><br>
</span><span>> Sent: Saturday, 27 September, 2014 7:18:25 PM<br>
</span><div><div>> Subject: Re: [FieldTrip] Where to add a trialfun?<br>
> Thank you Nietzsche!<br>
><br>
><br>
> I added it where you suggested and now this is the error I get:<br>
><br>
><br>
><br>
> Error using feval<br>
> Invalid function name 'trialfun_bit2dec(cfg)'.<br>
><br>
><br>
> Error in definetrial (line 105)<br>
> trl = feval(cfg.trialfun, cfg);<br>
><br>
><br>
> Error in process_ERP_1_fieldtrip (line 97)<br>
> cfg = definetrial(cfg);<br>
><br>
><br>
> Something I was worried about is that I use an old version of<br>
> Fieldtrip for my scripts because I wrote them long ago and this<br>
> trialfun uses the new format (with 'ft_s',etc.). Could this affect it<br>
> in any way?<br>
><br>
><br>
> Thanks again!<br>
><br>
><br>
> On Fri, Sep 26, 2014 at 11:05 PM, Lam, Nietzsche <<br>
> <a href="mailto:n.lam@fcdonders.ru.nl" target="_blank">n.lam@fcdonders.ru.nl</a> > wrote:<br>
><br>
><br>
> Hi Ana Laura,<br>
><br>
> In general, you need to determine which trial function (Trialfun) to<br>
> use when using definetrial (see this tutorial:<br>
> <a href="http://fieldtrip.fcdonders.nl/tutorial/preprocessing" target="_blank">http://fieldtrip.fcdonders.nl/tutorial/preprocessing</a> under "do the<br>
> trial definition for the fully incongruent (FIC) condition).<br>
><br>
> Please try adding this: "cfg.trialfun = 'trialfun_bit2dec(cfg)". to<br>
> your code before calling definetrial (see below).<br>
><br>
> % TRIAL DEFINITION<br>
> cfg=[];<br>
> cfg.filename = ['my/folders/', subject, '.RAW'];<br>
> cfg.headerfile = ['my/folders/', subject, '.RAW'];<br>
><br>
> cfg.trialdef.eventtype = 'STATUS';<br>
> cfg.trialdef.eventvalue = cgrmrk;<br>
> cfg.trialdef.prestim = 0.2;<br>
> cfg.trialdef.poststim = 1;<br>
> cfg.trialdef.eventtype=?;<br>
> cfg.trialfun = 'trialfun_bit2dec(cfg) %% trialfun definition<br>
> cfg = definetrial(cfg);<br>
><br>
><br>
> As an addition note: based on your error message, it seemed that the<br>
> problem was in the function trialfun_bit2dec. However, from the code<br>
> you showed us, you haven't referenced/called this function. I was<br>
> wondering if the code you provide corresponded to the code that<br>
> created your error message? I'm guessing you ran [trl]<br>
> =trialfun_bit2dec(cfg) directly (i.e. not via definetrial). In which<br>
> case, it was looking for cfg.trialdef.eventtype. You can call<br>
> trialfun_bit2dec as long as you have all the relevant information in<br>
> the cfg (which is in the code you showed us). Hope this helps.<br>
><br>
> Best,<br>
> Nietzsche<br>
><br>
><br>
><br>
><br>
><br>
><br>
> ----- Original Message -----<br>
> > From: "Ana Laura Diez Martini" < <a href="mailto:diezmartini@gmail.com" target="_blank">diezmartini@gmail.com</a> ><br>
> > To: "FieldTrip discussion list" < <a href="mailto:fieldtrip@science.ru.nl" target="_blank">fieldtrip@science.ru.nl</a> ><br>
> > Sent: Saturday, 27 September, 2014 2:42:21 AM<br>
> > Subject: [FieldTrip] Where to add a trialfun?<br>
> > Hello all! I'm having a simple problem. I want to add this trialfun:<br>
> ><br>
> > <a href="http://fieldtrip.fcdonders.nl/faq/how_can_i_transform_trigger_values_from_bits_to_decimal_representation_with_a_trialfun" target="_blank">http://fieldtrip.fcdonders.nl/faq/how_can_i_transform_trigger_values_from_bits_to_decimal_representation_with_a_trialfun</a><br>
> ><br>
> ><br>
> ><br>
> > I get this error:<br>
> ><br>
> ><br>
> ><br>
> > Reference to non-existent field 'trialdef'.<br>
> ><br>
> ><br>
> > Error in trialfun_bit2dec (line 52)<br>
> > if strcmp(event(i).type, cfg.trialdef.eventtype)<br>
> ><br>
> ><br>
> > I'm quite sure it's because I'm not writing it in the correct part<br>
> > of<br>
> > my script. This is my trial definition part. Where should I add it<br>
> > and<br>
> > how should I write the line?<br>
> ><br>
> ><br>
> ><br>
> > % TRIAL DEFINITION<br>
> > cfg=[];<br>
> > cfg.filename = ['my/folders/', subject, '.RAW'];<br>
> > cfg.headerfile = ['my/folders/', subject, '.RAW'];<br>
> ><br>
> ><br>
> > cfg.trialdef.eventtype = 'STATUS';<br>
> > cfg.trialdef.eventvalue = cgrmrk;<br>
> > cfg.trialdef.prestim = 0.2;<br>
> > cfg.trialdef.poststim = 1;<br>
> > cfg.trialdef.eventtype=?;<br>
> ><br>
> ><br>
> > cfg = definetrial(cfg);<br>
> ><br>
> ><br>
> > trl = cfg.trl;<br>
> > cfg=[];<br>
> > cfg.dataset = ['my/folders/', subject, '.RAW'];<br>
> > cfg.trl = trl;<br>
> > cfg.reref = 'yes';<br>
> > cfg.refchannel = ['all'];<br>
> ><br>
> ><br>
> > THANKS!<br>
> > _______________________________________________<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>
><br>
> --<br>
> Nietzsche H.L. Lam, MSc<br>
> PhD Candidate<br>
><br>
> Max Planck Institute for Psycholinguistics<br>
> Wundtlaan 1, 6525 XD Nijmegen, The Netherlands<br>
><br>
> Donders Institute for Brain, Cognition and Behaviour,<br>
> Centre for Cognitive Neuroimaging,<br>
> Kapittelweg 29, 6525EN Nijmegen, The Netherlands<br>
><br>
> <a href="mailto:n.lam@fcdonders.ru.nl" target="_blank">n.lam@fcdonders.ru.nl</a><br>
> <a href="tel:%2B31-24-3668219" value="+31243668219" target="_blank">+31-24-3668219</a><br>
><br>
><br>
> <a href="http://neurobiologyoflanguage.com" target="_blank">neurobiologyoflanguage.com</a><br>
> _______________________________________________<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>
><br>
><br>
> _______________________________________________<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>
<br>
--<br>
Nietzsche H.L. Lam, MSc<br>
PhD Candidate<br>
<br>
Max Planck Institute for Psycholinguistics<br>
Wundtlaan 1, 6525 XD Nijmegen, The Netherlands<br>
<br>
Donders Institute for Brain, Cognition and Behaviour,<br>
Centre for Cognitive Neuroimaging,<br>
Kapittelweg 29, 6525EN Nijmegen, The Netherlands<br>
<br>
<a href="mailto:n.lam@fcdonders.ru.nl" target="_blank">n.lam@fcdonders.ru.nl</a><br>
<a href="tel:%2B31-24-3668219" value="+31243668219" target="_blank">+31-24-3668219</a><br>
<br>
<br>
<a href="http://neurobiologyoflanguage.com" target="_blank">neurobiologyoflanguage.com</a><br>
_______________________________________________<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>
</div></div></blockquote></div><br></div>
</div></div><br>_______________________________________________<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></div>
</div></div><br>_______________________________________________<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></div>
</div></div></blockquote></div><br></div>
</div></div><br>_______________________________________________<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></div>
</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><br></div>