error in prepare_leadfield

Robert Oostenveld r.oostenveld at FCDONDERS.RU.NL
Fri Nov 14 10:10:20 CET 2008

Hi Michiel,

The progress function is used to print the progress (or to make a
graphical progress bar). Matlab has the waitbar function, but that is
very slow if you update it every iteration. E.g. consider 10000
iterations, and the width of the graphical waitbar on your screen only
being 60 pixels. Updating the waitbar on every iteration makes it very
slow, so it only updates every 1% increase.

This is implemented using persistent variables, i.e. the progress
function remembers the state of the progress over subsequent calls. It
seems to me in the error that you report below, that the persistent
variable was somehow cleared in between two calls. That happens if you
clear the function (see "help clear") or when matlab detects that teh
function has changed. Perhaps your fieldtrip installation was updated
while matlab was running? That may (actually should) happen
automatically if you run it from home/common on the FCDC. The progress
function does not change very often, but recently I did make some
change to it (and that will have been autoupdated on home/common),
which may explain the problem.

I suggest you simply try again.


On 5 Nov 2008, at 17:08, Michiel van Elk wrote:

> The 'prepare_leadfield' seems to run fine, but after a couple of hours
> I get the following error message (note that I removed the 'computing
> leadfield' statements):
> selected 60 electrodes
> projecting electrodes on skin surface
> combining electrode transfer and system matrix
> 791211 dipoles inside, 7215640 dipoles outside brain
> making tight grid
> 791211 dipoles inside, 692565 dipoles outside brain
> ??? SWITCH expression must be a scalar or string constant.
> Error in ==> progress at 94
>  switch t
> Error in ==> prepare_leadfield at 236
> progress('close');
> Does someone have a clue what could have gone wrong in this
> analysis? I
> used the following cfg settings (e.g. is it correct to convert the
> elec.pnt from
> cm to mm?)

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