problems using fieldtrip

J.M. Schoffelen Jan.Schoffelen at FCDONDERS.RU.NL
Tue Aug 9 17:14:32 CEST 2005

Dear Hoi Fei,

I think I have a clue of what is going on:

 if ctferror && haseegsf

This is the thing that should not occur, so for some reason or another both
haseegsf and ctferror are true:

This means that somewhere in your path you have the files ctf_read_meg4, and
ctf_read_res4, which usually is no problem, but in this case is half of your
problem, because it makes the if-statement already half true.
Next to this ctferror apparently is true, which should not be the case. It
goes wrong in line 130, where ctferror is put to one after the catch, so the
try did not work out too well. I would say that this could be caused by the
fact that you lack the function read_ctf_res4 altogether, which should be
located in the private-subdirectory of fieldtrip. This does not seem too
likely to me, so I would guess that somehow the headerfile in line 126 is
incorrecly formatted. To get an idea if this is the case, try to put a
breakpoint in line 127 or so.
Are you at the right location with Matlab? I.e., if you type "pwd",
does that correspond with the directory where Subject01.ds is located? This
might also be the problem.

Hope this helps a bit,



    % try to read it using the CTF importer from the NIH and Daren Weber
      tmp = ctf_read_res4(fileparts(headerfile), 0);
      ctferror = 0;
      % convert the header into a structure that FieldTrip understands
      hdr              = [];
      hdr.Fs           = tmp.setup.sample_rate;
      hdr.nChans       = length(;
      hdr.nSamples     = tmp.setup.number_samples;
      hdr.nSamplesPre  = tmp.setup.pretrigger_samples;
      hdr.nTrials      = tmp.setup.number_trials;
      for i=1:length(
        hdr.label{i}   =;
      hdr.label        = hdr.label(:);
      % add a gradiometer structure for forward and inverse modelling
      hdr.grad         = nimh2grad(tmp);
      % also store the original header, so that it can be reused by
      hdr.orig         = tmp;
      ctferror = 1;
  if ctferror
    error('could not read CTF res4 header file');

In the above section of codes, the hdr is redefined and then on line 151,
the variable tmp is passed as an input argument for 'nimh2grad'. On line 22
of nimh2grad:

sel = hdr.sensor.index.meg;

now hdr is tmp (as tmp is the input argument). However, when I examined tmp
after coming out of the function, I found that there isn't a field
tmp.sensor.index.meg. Instead, I found things like the meg_left_central,
meg_left_frontal, etc but just not 'meg'. Therefore, I think sel was
assigned as an empty matrix and that implies length(sel)=0 and so the for
loop starting from line 30 of 'nimh2grad.m' was not executed.

I am not sure if you agree with my conclusion and if anything can be done
about it.

Hoi Fei

-----Original Message-----
From: FieldTrip discussion list [mailto:FIELDTRIP at NIC.SURFNET.NL] On Behalf
Of Robert Oostenveld
Sent: 09 August 2005 14:39
Subject: Re: [FIELDTRIP] problems using fieldtrip

Dear Hoi Fei

On 9-aug-2005, at 15:05, Hoi Fei Kwok wrote:
> This is the first time that I am using FieldTrip. Just like to ask
> what
> other software are needed besides MATLAB in order to run the
> tutorials. I

Some parts of the tutorials use CTF specific applications. That is
commercial software only available to CTF MEG users. However, you can
skip those parts of the tutorial. Furthermore, I think that there is
a tutorial that refers to MRIcro, you can get that here: http://

> have tried to run the tutorials after downloading and unzipping the
> but I ran into problems.
> Firstly, in the Event Related Averaging tutorial, the
> EventRelatedAveraging.m was mentioned but I could not find the file.

you can copy and paste all matlab instructions from the pdf into the
matlab command line window. I will also make the demo scripts
available for download on the website, but I won't be able to do that

> Secondly, after I created a cfg structure with 'Subject01.ds' as the
> dataset and all the other field properties as instructed in the
> tutorial, I
> got the following error message when using the preprocessing.m:
> CTF_READ_RES4 [v  1.12]
> ??? Error using ==> read_fcdc_header
> could not read CTF res4 header file
> Error in ==> preprocessing at 219
> hdr = read_fcdc_header(cfg.headerfile);

Are you at the right location with Matlab? I.e., if you type "pwd",
does that correspond with the directory where Subject01.ds is located?

best regards,

More information about the fieldtrip mailing list