[FieldTrip] Where to add a trialfun?

Ana Laura Diez Martini diezmartini at gmail.com
Sun Oct 5 22:34:35 CEST 2014


Hi Jorn and all,

As I said before, everything works ok when I use ft_trialfun_general
instead of this trialfun. However, it is crucial for me to transform the
event values with that trialfun. And now I use 'trigger' instead of
'STATUS' but it doesn't change much.  Any other idea? THANK YOU!

This is my script again:

% CONGRUENT TRIALS DEFINITION

cfg = [ ] ;
cfg.dataset    = 'location';
event = ft_read_event('location');
cfg.trialdef.eventtype = 'trigger';
cfg.trialdef.eventvalue = cgrmrk;
cfg.trialdef.prestim    = 0.2;
cfg.trialdef.poststim   = 1;
cfg.trialfun   = 'trialfun_bit2dec';
[cfg] = ft_definetrial(cfg);

On Wed, Oct 1, 2014 at 4:03 AM, "Jörn M. Horschig" <
jm.horschig at donders.ru.nl> wrote:

> Hi Ana,
>
> from the first call with eventtype = '?', the output says
>
>> event type: 'trigger' with event values: 'DIN1' 'DIN2' 'DIN4' 'DIN8'
>>
>
> This means that there is one event type in our data, namely 'trigger', and
> the only trigger values in your data are 'DIN1', 'DIN2', 'DIN4' and 'DIN8'.
> FieldTrip works that way that it passes on the cfg.trialdef structure to
> the trialfun that is specified. In your particular case, trialfun_bit2dec
> does not seem to have a very user-friendly error message, but the error
> message means that whatever eventtype and eventvalues you asked for, they
> are not present in your data. When looking at what you define, you can
> probably easily spot that you ask for cfg.trialdef.eventtype = 'STATUS'.
> However, checking back the output that you created with '?', there is no
> event type 'STATUS' in your data. Therefore, everything works fine with
> your trialfun. If you try specifying the trialdef properly, everything
> should work fine.
>
> A general advise when using an own trial fun and getting an error message:
> Try your code without specifying cfg.trialfun first. Then FieldTrip will
> use the standard trialfun, which should work if all your cfg-settings are
> fine. If the standard trialfun runs without errors, then your trialfun
> should do so too. If your trialfun, however, then crashes, the error is
> most likely in the trialfun that you used, and not in the cfg-settings. In
> your case, however, I am fairly certain that the cfg-settings you specified
> were causing your problem.
>
> I hope this helps.
> Best,
> Jörn
>
>
>
>
> On 9/30/2014 10:27 PM, Ana Laura Diez Martini wrote:
>
>> 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:
>>
>>  >> cfg = [];
>> >> cfg.dataset = '27CW1.RAW';
>> >> cfg.trialdef.eventtype  = '?';
>> >> cfg=ft_definetrial(cfg);
>>
>> Warning: no trialfun was specified, using ft_trialfun_general
>> > In ft_definetrial at 135
>> evaluating trialfunction 'ft_trialfun_general'
>> reading the events from '27CW1.RAW'
>> the following events were found in the datafile
>> event type: 'trigger' with event values: 'DIN1' 'DIN2' 'DIN4' 'DIN8'
>> no trials have been defined yet, see FT_DEFINETRIAL for further help
>> found 750 events
>> created 0 trials
>> the call to "ft_definetrial" took 4 seconds
>>
>> Then I try to use the trialfun, I get the same error
>>
>> >> cfg = [];
>> >> cfg.dataset = '27CW1.RAW';
>> >> cfg.trialfun   = 'trialfun_bit2dec';
>> >> cfg.trialdef.eventtype  = '?';
>> >> cfg=ft_definetrial(cfg);
>> evaluating trialfunction 'trialfun_bit2dec'
>>
>> 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);
>>
>> So there is something the trialfun_bit2dec does that events cannot be
>> read anymore.
>>
>>
>> On Mon, Sep 29, 2014 at 9:01 PM, Arjen Stolk <a.stolk8 at gmail.com <mailto:
>> a.stolk8 at gmail.com>> wrote:
>>
>>     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 <mailto: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 <mailto: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 <mailto: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 <mailto: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
>>                     <mailto: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
>>                         <mailto:diezmartini at gmail.com>>
>>                         > To: "FieldTrip discussion list"
>>                         <fieldtrip at science.ru.nl
>>                         <mailto: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
>>                         <mailto: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
>>                         <mailto:diezmartini at gmail.com> >
>>                         > > To: "FieldTrip discussion list" <
>>                         fieldtrip at science.ru.nl
>>                         <mailto: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
>>                         <mailto: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
>>                         <mailto:n.lam at fcdonders.ru.nl>
>>                         > +31-24-3668219 <tel:%2B31-24-3668219>
>>                         >
>>                         >
>>                         > neurobiologyoflanguage.com
>>                         <http://neurobiologyoflanguage.com>
>>                         > _______________________________________________
>>                         > fieldtrip mailing list
>>                         > fieldtrip at donders.ru.nl
>>                         <mailto:fieldtrip at donders.ru.nl>
>>                         >
>>                         http://mailman.science.ru.nl/
>> mailman/listinfo/fieldtrip
>>                         >
>>                         >
>>                         > _______________________________________________
>>                         > fieldtrip mailing list
>>                         > fieldtrip at donders.ru.nl
>>                         <mailto: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
>>                         <mailto:n.lam at fcdonders.ru.nl>
>>                         +31-24-3668219 <tel:%2B31-24-3668219>
>>
>>
>>                         neurobiologyoflanguage.com
>>                         <http://neurobiologyoflanguage.com>
>>                         _______________________________________________
>>                         fieldtrip mailing list
>>                         fieldtrip at donders.ru.nl
>>                         <mailto:fieldtrip at donders.ru.nl>
>>                         http://mailman.science.ru.nl/
>> mailman/listinfo/fieldtrip
>>
>>
>>
>>                     _______________________________________________
>>                     fieldtrip mailing list
>>                     fieldtrip at donders.ru.nl
>>                     <mailto:fieldtrip at donders.ru.nl>
>>                     http://mailman.science.ru.nl/
>> mailman/listinfo/fieldtrip
>>
>>
>>
>>                 _______________________________________________
>>                 fieldtrip mailing list
>>                 fieldtrip at donders.ru.nl <mailto:fieldtrip at donders.ru.nl>
>>                 http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>
>>
>>
>>
>>         _______________________________________________
>>         fieldtrip mailing list
>>         fieldtrip at donders.ru.nl <mailto:fieldtrip at donders.ru.nl>
>>         http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>
>>
>>
>>     _______________________________________________
>>     fieldtrip mailing list
>>     fieldtrip at donders.ru.nl <mailto: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
>>
>
>
> --
> Jörn M. Horschig
> PhD Student
> Donders Institute for Brain, Cognition and Behaviour
> Centre for Cognitive Neuroimaging
> Radboud University Nijmegen
> Neuronal Oscillations Group
> FieldTrip Development Team
>
> P.O. Box 9101
> NL-6500 HB Nijmegen
> The Netherlands
>
> Contact:
> E-Mail: jm.horschig at donders.ru.nl
> Tel:    +31-(0)24-36-68493
> Web: http://www.ru.nl/donders
>
> Visiting address:
> Trigon, room 2.30
> Kapittelweg 29
> NL-6525 EN Nijmegen
> The Netherlands
>
>
> _______________________________________________
> 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/20141005/18c7ee72/attachment-0002.html>


More information about the fieldtrip mailing list