In general you should not add fieldtrip with all subdirectories to your path. There are a number of external toolboxes (in fieldtrip/external) which are irrelevant for most users, and even can cause some problems if they overlap with other (custom) toolboxes on your path.

You should do

addpath <full_path_to_fieldtrip>

where full_path_to_fieldtrip is the location where the fieldtrip directory is located. Inside the Donders Centre, this would be

addpath /home/common/matlab/fieldtrip

whereas on your computer it might be

addpath D:\fieldtrip-20100228

After adding the fieldtrip main path, you should execute the ft_defaults function (formerly called fieldtripdefs.m), which sets the defaults and configures up the minimal required path settings.


It is most convenient to have the addpath and ft_defaults in a startup.m script, which is located in your own MATLAB directory. See this information from Mathworks.

Please be aware that you should NOT do

because that will add many toolbox directories to your path that you won't use. Furthermore, it potentially causes some toolboxes to be on your path twice (e.g. SPM).

If you want to ensure that you have a clean version of the FieldTrip toolbox on your MATLAB path, please do

addpath /home/common/matlab/fieldtrip

All other dependencies will subsequently be added automatically when needed.

In case FieldTrip function needs additional functions (e.g. for reading a specific data format such as CTF, or for performing a specific computation such as runica), it uses the utilities/ft_hastoolbox.m helper function to determine whether a toolbox is present. If the toolbox is present on your path, it will not add it once more. If the toolbox “xxx” is not yet present, but the directory seems to be present in fieldtrip/external/xxx, then it will add that directory to your path.

The main FieldTrip functions such as ft_preprocessing and ft_freqanalysis all call the ft_defaults function at the beginning. The ft_defaults function ensures that the required subdirectories such as fieldtrip/preproc and fieldtrip/fileio are added. All other toolboxes in fieldtrip/external will only be added upon request, i.e. only when a function from one of those toolboxes is really needed.

You might be worried that this automatic path-checking and path-adding on every function call makes it slow. The utilities/ft_hastoolbox.m remembers (with a persistent variable) whether a certain toolbox has already been checked, and therefore does not check the same toolbox twice. (Note: in case fieldtrip folders are removed, for instance by using rmpath or restoredefaultpath, make sure to reset the persistent variable in the hastoolbox function again by executing: clear ft_hastoolbox)