[FieldTrip] Where to add a trialfun?

Arjen Stolk a.stolk8 at gmail.com
Tue Sep 30 09:01:11 CEST 2014


Hi Ana Laura,

Your 'trl' is empty, which it shouldn't be. So anytime you try to index an
element in it, it will throw an error.

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]".

Goodluck,
Arjen

2014-09-30 6:20 GMT+02:00 Ana Laura Diez Martini <diezmartini at gmail.com>:

> This is my attempt of adapting the code for the new Fieldtrip
>
>  % TRIAL DEFINITION
>
>     cfg=[];
>     cfg.dataset = 'myfile';
>
>     hdr = ft_read_header( 'myfile');
>     dat = ft_read_data('myfile');
>     cfg.trialfun                = 'trialfun_bit2dec';
>     cfg.trialdef.eventtype    = 'STATUS';
>     cfg.trialdef.eventvalue   = cgrmrk; % stimulus triggers
>     cfg.trialdef.prestim      = 0.2;
>     cfg.trialdef.poststim     = 1;
>
>     cfg.reref         = 'yes';
>     cfg.refchannel    = ['all'];
>     cfg = ft_definetrial(cfg);
>
> again the error is:
>
> Attempted to access trl(:,1); index out of bounds because size(trl)=[0,0].
>
> Error in trialfun_bit2dec (line 66)
> idx = any(diff(trl(:,1),1,1),2);
>
> Error in ft_definetrial (line 169)
>     trl   = feval(cfg.trialfun, cfg);
>
> Error in process_ERP_1_fieldtrip (line 106)
>     cfg = ft_definetrial(cfg);
>
>
>
> On Mon, Sep 29, 2014 at 12:11 PM, Ana Laura Diez Martini <
> diezmartini at gmail.com> wrote:
>
>> Dear Arjen and Nietzsche,
>>
>> I tried debugging with dbstop if error and cfg.debug = 'saveonerror' and
>> matlab points to:
>>
>> % discard the repeated values
>> idx = any(diff(trl(:,1),1,1),2);
>> trl = trl(idx,:);
>>
>> 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?
>>
>> On Mon, Sep 29, 2014 at 8:57 AM, Arjen Stolk <a.stolk8 at gmail.com> wrote:
>>
>>> Hey Ana Laura,
>>>
>>> Seems from the error message you're getting
>>>
>>> "Attempted to access trl(:,1); index out of bounds because
>>> size(trl)=[0,0]."
>>>
>>> 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.
>>>
>>> Best,
>>> Arjen
>>>
>>>
>>>
>>> 2014-09-29 19:00 GMT+02:00 Ana Laura Diez Martini <diezmartini at gmail.com
>>> >:
>>>
>>>> Thank you again Nietzsche!!
>>>>
>>>> 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:
>>>>
>>>> Attempted to access trl(:,1); index out of bounds because
>>>> size(trl)=[0,0].
>>>>
>>>> Error in trialfun_bit2dec (line 66)
>>>> idx = any(diff(trl(:,1),1,1),2);
>>>>
>>>> Error in ft_definetrial (line 169)
>>>>     trl   = feval(cfg.trialfun, cfg);
>>>>
>>>> Error in process_ERP_1_fieldtrip (line 95)
>>>>     cfg = ft_definetrial(cfg);
>>>>
>>>> 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.
>>>>
>>>>   % TRIAL DEFINITION
>>>>     cfg=[];
>>>>     cfg.filename = ['myfolders/subject.RAW'];
>>>>     cfg.headerfile = ['myfolders/subject.RAW'];
>>>>     cfg.dataset = ['myfolders/subject.RAW'];
>>>>     cfg.trialfun   = 'trialfun_bit2dec';  %% trialfun definition
>>>>     cfg.trialdef.eventtype    = 'STATUS';
>>>>     cfg.trialdef.eventvalue   = cgrmrk; % stimulus triggers
>>>>     cfg.trialdef.prestim      = 0.2; % latency in seconds
>>>>     cfg.trialdef.poststim     = 1;   % latency in seconds
>>>>     cfg = ft_definetrial(cfg);
>>>>
>>>>     trl = cfg.trl;
>>>>     cfg=[];
>>>>     cfg.dataset = ['myfolders/subject.RAW'];
>>>>     cfg.trl           = trl;
>>>>     cfg.reref         = 'yes';
>>>>     cfg.refchannel    = ['all'];
>>>>
>>>> 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.
>>>>
>>>> On Sun, Sep 28, 2014 at 10:53 PM, Lam, Nietzsche <n.lam at fcdonders.ru.nl
>>>> > wrote:
>>>>
>>>>> Hi again Ana Laura,
>>>>>
>>>>> 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.
>>>>>
>>>>> 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.
>>>>>
>>>>> Nietzsche
>>>>>
>>>>> ----- Original Message -----
>>>>> > From: "Ana Laura Diez Martini" <diezmartini at gmail.com>
>>>>> > To: "FieldTrip discussion list" <fieldtrip at science.ru.nl>
>>>>> > Sent: Saturday, 27 September, 2014 7:18:25 PM
>>>>> > Subject: Re: [FieldTrip] Where to add a trialfun?
>>>>> > Thank you Nietzsche!
>>>>> >
>>>>> >
>>>>> > I added it where you suggested and now this is the error I get:
>>>>> >
>>>>> >
>>>>> >
>>>>> > Error using feval
>>>>> > Invalid function name 'trialfun_bit2dec(cfg)'.
>>>>> >
>>>>> >
>>>>> > Error in definetrial (line 105)
>>>>> > trl = feval(cfg.trialfun, cfg);
>>>>> >
>>>>> >
>>>>> > Error in process_ERP_1_fieldtrip (line 97)
>>>>> > cfg = definetrial(cfg);
>>>>> >
>>>>> >
>>>>> > Something I was worried about is that I use an old version of
>>>>> > Fieldtrip for my scripts because I wrote them long ago and this
>>>>> > trialfun uses the new format (with 'ft_s',etc.). Could this affect it
>>>>> > in any way?
>>>>> >
>>>>> >
>>>>> > Thanks again!
>>>>> >
>>>>> >
>>>>> > On Fri, Sep 26, 2014 at 11:05 PM, Lam, Nietzsche <
>>>>> > n.lam at fcdonders.ru.nl > wrote:
>>>>> >
>>>>> >
>>>>> > Hi Ana Laura,
>>>>> >
>>>>> > In general, you need to determine which trial function (Trialfun) to
>>>>> > use when using definetrial (see this tutorial:
>>>>> > http://fieldtrip.fcdonders.nl/tutorial/preprocessing under "do the
>>>>> > trial definition for the fully incongruent (FIC) condition).
>>>>> >
>>>>> > Please try adding this: "cfg.trialfun = 'trialfun_bit2dec(cfg)". to
>>>>> > your code before calling definetrial (see below).
>>>>> >
>>>>> > % TRIAL DEFINITION
>>>>> > cfg=[];
>>>>> > cfg.filename = ['my/folders/', subject, '.RAW'];
>>>>> > cfg.headerfile = ['my/folders/', subject, '.RAW'];
>>>>> >
>>>>> > cfg.trialdef.eventtype = 'STATUS';
>>>>> > cfg.trialdef.eventvalue = cgrmrk;
>>>>> > cfg.trialdef.prestim = 0.2;
>>>>> > cfg.trialdef.poststim = 1;
>>>>> > cfg.trialdef.eventtype=?;
>>>>> > cfg.trialfun = 'trialfun_bit2dec(cfg) %% trialfun definition
>>>>> > cfg = definetrial(cfg);
>>>>> >
>>>>> >
>>>>> > As an addition note: based on your error message, it seemed that the
>>>>> > problem was in the function trialfun_bit2dec. However, from the code
>>>>> > you showed us, you haven't referenced/called this function. I was
>>>>> > wondering if the code you provide corresponded to the code that
>>>>> > created your error message? I'm guessing you ran [trl]
>>>>> > =trialfun_bit2dec(cfg) directly (i.e. not via definetrial). In which
>>>>> > case, it was looking for cfg.trialdef.eventtype. You can call
>>>>> > trialfun_bit2dec as long as you have all the relevant information in
>>>>> > the cfg (which is in the code you showed us). Hope this helps.
>>>>> >
>>>>> > Best,
>>>>> > Nietzsche
>>>>> >
>>>>> >
>>>>> >
>>>>> >
>>>>> >
>>>>> >
>>>>> > ----- Original Message -----
>>>>> > > From: "Ana Laura Diez Martini" < diezmartini at gmail.com >
>>>>> > > To: "FieldTrip discussion list" < fieldtrip at science.ru.nl >
>>>>> > > Sent: Saturday, 27 September, 2014 2:42:21 AM
>>>>> > > Subject: [FieldTrip] Where to add a trialfun?
>>>>> > > Hello all! I'm having a simple problem. I want to add this
>>>>> trialfun:
>>>>> > >
>>>>> > >
>>>>> http://fieldtrip.fcdonders.nl/faq/how_can_i_transform_trigger_values_from_bits_to_decimal_representation_with_a_trialfun
>>>>> > >
>>>>> > >
>>>>> > >
>>>>> > > I get this error:
>>>>> > >
>>>>> > >
>>>>> > >
>>>>> > > Reference to non-existent field 'trialdef'.
>>>>> > >
>>>>> > >
>>>>> > > Error in trialfun_bit2dec (line 52)
>>>>> > > if strcmp(event(i).type, cfg.trialdef.eventtype)
>>>>> > >
>>>>> > >
>>>>> > > I'm quite sure it's because I'm not writing it in the correct part
>>>>> > > of
>>>>> > > my script. This is my trial definition part. Where should I add it
>>>>> > > and
>>>>> > > how should I write the line?
>>>>> > >
>>>>> > >
>>>>> > >
>>>>> > > % TRIAL DEFINITION
>>>>> > > cfg=[];
>>>>> > > cfg.filename = ['my/folders/', subject, '.RAW'];
>>>>> > > cfg.headerfile = ['my/folders/', subject, '.RAW'];
>>>>> > >
>>>>> > >
>>>>> > > cfg.trialdef.eventtype = 'STATUS';
>>>>> > > cfg.trialdef.eventvalue = cgrmrk;
>>>>> > > cfg.trialdef.prestim = 0.2;
>>>>> > > cfg.trialdef.poststim = 1;
>>>>> > > cfg.trialdef.eventtype=?;
>>>>> > >
>>>>> > >
>>>>> > > cfg = definetrial(cfg);
>>>>> > >
>>>>> > >
>>>>> > > trl = cfg.trl;
>>>>> > > cfg=[];
>>>>> > > cfg.dataset = ['my/folders/', subject, '.RAW'];
>>>>> > > cfg.trl = trl;
>>>>> > > cfg.reref = 'yes';
>>>>> > > cfg.refchannel = ['all'];
>>>>> > >
>>>>> > >
>>>>> > > THANKS!
>>>>> > > _______________________________________________
>>>>> > > fieldtrip mailing list
>>>>> > > fieldtrip at donders.ru.nl
>>>>> > > http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>>>> >
>>>>> > --
>>>>> > Nietzsche H.L. Lam, MSc
>>>>> > PhD Candidate
>>>>> >
>>>>> > Max Planck Institute for Psycholinguistics
>>>>> > Wundtlaan 1, 6525 XD Nijmegen, The Netherlands
>>>>> >
>>>>> > Donders Institute for Brain, Cognition and Behaviour,
>>>>> > Centre for Cognitive Neuroimaging,
>>>>> > Kapittelweg 29, 6525EN Nijmegen, The Netherlands
>>>>> >
>>>>> > n.lam at fcdonders.ru.nl
>>>>> > +31-24-3668219
>>>>> >
>>>>> >
>>>>> > neurobiologyoflanguage.com
>>>>> > _______________________________________________
>>>>> > fieldtrip mailing list
>>>>> > fieldtrip at donders.ru.nl
>>>>> > http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>>>> >
>>>>> >
>>>>> > _______________________________________________
>>>>> > fieldtrip mailing list
>>>>> > fieldtrip at donders.ru.nl
>>>>> > http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>>>>
>>>>> --
>>>>> Nietzsche H.L. Lam, MSc
>>>>> PhD Candidate
>>>>>
>>>>> Max Planck Institute for Psycholinguistics
>>>>> Wundtlaan 1, 6525 XD Nijmegen, The Netherlands
>>>>>
>>>>> Donders Institute for Brain, Cognition and Behaviour,
>>>>> Centre for Cognitive Neuroimaging,
>>>>> Kapittelweg 29, 6525EN Nijmegen, The Netherlands
>>>>>
>>>>> n.lam at fcdonders.ru.nl
>>>>> +31-24-3668219
>>>>>
>>>>>
>>>>> neurobiologyoflanguage.com
>>>>> _______________________________________________
>>>>> fieldtrip mailing list
>>>>> fieldtrip at donders.ru.nl
>>>>> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> fieldtrip mailing list
>>>> fieldtrip at donders.ru.nl
>>>> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>>>
>>>
>>>
>>> _______________________________________________
>>> fieldtrip mailing list
>>> fieldtrip at donders.ru.nl
>>> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>>
>>
>>
>
> _______________________________________________
> fieldtrip mailing list
> fieldtrip at donders.ru.nl
> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20140930/a424f4a2/attachment-0002.html>


More information about the fieldtrip mailing list