help with reading .fif files in Fieldtrip

Christian Hesse c.hesse at FCDONDERS.RU.NL
Tue Mar 13 09:04:22 CET 2007

Hi Matthew,

In addition to Lauri's remarks about making sure that the MEG-PD and
MATLAB you're using are indeed compatible and fully aware of each
other, it would be helpful if you could try the following lines of
code in Matlab (which uses FieldTrip reading functions) and send us
the screen output:

% specify filename
filename = 'fullpath/name.fif';

% read the header
hdr = read_fcdc_header(filename);

% get the indices of the STI channels
idx = strmatch('STI',hdr.label);
% display them and the channel labels on screen as sanity check
% NOTE: if you know you use only one STI channel and you know which
one it is,
% e.g., 'STI 001' then you can also do this:
% idx = strmatch('STI 001',hdr.label);

% extract only the STI channels from the file
dat = read_fcdc_data(filename,'chanindx',idx);
% although Neuromag data is "continuous" it is actually written in
the file in blocks
% and reading only part of the data will return a 3-D array rather
than a 2-D array
% hence the reshape operation in the following
[nchans, nsamps, nblocks] = size(dat);
if (nblocks>1), dat = reshape(dat, [nchans, nsamps*nblocks]); end;
% this should be an nchans x ntotalsamples matirx

If all of these commands produce sensible output using your fif file,
then the problem has to do with the options being passed to
DEFINETRIAL (which uses the above lower level functions). But we
first need to establish that you have correctly set up MEG-PD, MATLAB
and FieldTrip, and that there is not a problem with the data file


On 12 Mar 2007, at 21:53, Shtrahman, Matthew wrote:

> Hi Lauri,
> Thanks for the email. I am using Matlab 7.3 and FiffAcess 1.2
> (release 4), which I believe is the latest version. Any other ideas
> perhaps?
> Thanks again,
> Matt
> ________________________________
> From: FieldTrip discussion list on behalf of Lauri Parkkonen
> Sent: Mon 3/12/2007 4:23 PM
> Subject: Re: [FIELDTRIP] help with reading .fif files in Fieldtrip
> Hi Matthew,
> Which Matlab version you're using? With a 7.x Matlab and the newest
> meg-pd (a.k.a FiffAccess) toolbox you should be able to read fif-files
> without extra configurations, however, the older 6.x Matlabs with the
> older meg-pd toolbox require setting the LD_ASSUME_KERNEL environment
> variable before starting Matlab. Using a 7.x Matlab with the older
> meg-pd package is likely to give the error messages you're quoting in
> your email.
> Best regards,
> Lauri
> Shtrahman, Matthew wrote:
>> Hello,
>> I am new to Fieldtrip and I am having difficulty getting the
>> fieldtrip function DEFINETRIAL to read continuous .fif (Neuromag)
>> files. I have installed the MEG-PD toolbox in my matlab path and
>> regularly use it in my own code to read the same .fif files with
>> no errors. I also have tried copying the toolbox files to the
>> fieldtrip/private directory. Regardless of what I do when I use
>> DEFINETRIAL Matlab crashes and I get the following error:
>> Warning: Error reading fif-file!
>> terminate called after throwing an instance of
>> 'MathWorks::System::_utException'
>> I simply adapted the settings for reading a continuous data set
>> from the tutorial:
>> cfg = [];
>> cfg.dataset = 'file.fif';
>> cfg.hearderfile = 'file.fif';
>> cfg.datatype = 'continuous';
>> cfg = definetrial(cfg);
>> I don't know if it makes a difference, but I have also tried
>> specifying the entire path for the file, working as root, and
>> including various configurations for definetrial included in the
>> tutorial (see end of email).
>> Does any one have any idea why Fieldtrip cannot read my .fif files?
>> Many thanks,
>> Matt
>> = {'0111'};
>> cfg.trialdef.eventtype  = 'backpanel trigger';
>> cfg.trialdef.eventvalue = 3;         % trigger for the FIC condition
>> cfg.trialdef.prestim    = 1;         % time in seconds before trigger
>> cfg.trialdef.poststim   = 2;         % time in seconds after trigger

Christian Hesse, PhD, MIEEE

F.C. Donders Centre for Cognitive Neuroimaging
P.O. Box 9101
NL-6500 HB Nijmegen
The Netherlands

Tel.: +31 (0)24 36 68293
Fax: +31 (0)24 36 10989

Email: c.hesse at

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the fieldtrip mailing list