megplanar input structure

Akiko Ikkai akiko at NYU.EDU
Mon Sep 20 23:54:46 CEST 2010


I'm trying to calculate the planar gradient for my MEG data. I have 2 questions:

1. in tutorial "Event related averaging and planar gradient", (ft_)megplanar appears to call for averaged data created with cfg.keeptrials = 'no'; (how it was calculated earlier in the page), which looks like: (from tutorial)

avgFIC =
         avg: [149x900 double]
         var: [149x900 double]
     fsample: 300
  numsamples: [77x1 double]
        time: [1x900 double]
         dof: [149x900 double]
       label: {149x1 cell}
      dimord: 'chan_time'
        grad: [1x1 struct]
         cfg: [1x1 struct]

However, megplanar looks for data.trial (e.g. line 252). If I feed in averaged data with  cfg.keeptrials = 'yes'; input structure looks like: (from my data, after timelockanalysis with cfg.keeptrials = 'yes';)

timelock =

        avg: [156x751 double]
        var: [156x751 double]
    fsample: 500
       time: [1x751 double]
        dof: [156x751 double]
      label: {1x156 cell}
      trial: [72x156x751 double]
     dimord: 'rpt_chan_time'
        cfg: [1x1 struct]

However, data.trial is matrix instead of cell structure, as megplanar requires (e.g. line 505:
interp.trial{i} = transform * data.trial{i}(dataindx,:);  ), it crashes here.

Also in tutorial, it appears that the sequence of analysis is ft_megplanar -> ft_timelockanalysis -> ft_combineplanar, where I suspect ft_timelockanalysis should be before calculating planar gradients...?

2. How to deal with bad channels in calculating planar gradient? It is suggested that we do preprocessing, timelockanalysis, megplanar and combineplanar. However, if I have bad channels and reject them in preprocessing, combineplanar crashes @ line 326

 if all(size(orig.pnt)==[302 3]) && ...
    all(size(orig.pnt)==[302 3]) && ...
    all(size(orig.tra)==[302 302]) && ...
    length(orig.label)==302 && ...

because length(orig.label) is not going to be 302. Could I simply change these lines to something like:

if all(size(orig.pnt)==[length(orig.label) 3]) && ...
    all(size(orig.pnt)==[length(orig.label) 3]) && ...
    all(size(orig.tra)==[length(orig.label) length(orig.label)]) && ...

If anyone could clarify these issues, I'd greatly appreciate it.
Thanks in advance! Akiko

The aim of this list is to facilitate the discussion between users of the FieldTrip  toolbox, to share experiences and to discuss new ideas for MEG and EEG analysis. See also and

More information about the fieldtrip mailing list