[Eeglablist] Advanced source reconstruction using DIPFIT/Fieldtrip issue

Matteo Panizzolo Terrin matteo.panizzoloterrin at studenti.unipd.it
Tue Jun 13 03:37:10 PDT 2023


Dear EEGLAB community,

I'm a beginner EEGLAB user, I'm trying to follow the manual
(<a href="https://urldefense.com/v3/__https://eeglab.org/tutorials/09_source/EEG_sources.html__;!!Mih3wA!H4dDLJg14AcHS5nBa28FmZNU6Ij9aRLZS-twHMOgjJrVxG0k_yyrl1i9ecaIPVfzVqKb2XJkZqJLfVawbA_RGpOTAwQjmwinpabHJgD0vA$">https://eeglab.org/tutorials/09_source/EEG_sources.html</a>) in order to
practice source localization.

In particular I just tried to copy and paste the script described
about  the 'Advanced source reconstruction using DIPFIT/Fieldtrip'.

I get this error and I don't know how to fix it:

Undefined function 'abs' for input arguments of type 'cell'.

Error in ft_sourceplot (line 455)
    fun = abs(fun);

Error in advanced_dipole_fit_modified (line 70)
figure; ft_sourceplot(cfg, sourceProj);


I hope you can help me out somehow, thank you in advance.


Matteo


The script:

%% First load a dataset in EEGLAB.
% Then use EEGLAB menu item <em>Tools > Locate dipoles using DIPFIT >
Head model and settings</em>
% to align electrode locations to a head model of choice
% The eeglab/fieldtrip code is shown below:

eeglab                        % start eeglab
eeglabPath = fileparts(which('eeglab'));                 % save its location
bemPath = fullfile(eeglabPath, 'plugins', 'dipfit', 'standard_BEM');
 % load the dipfit plugin
EEG = pop_loadset(fullfile(eeglabPath, 'sample_data',
'eeglab_data_epochs_ica.set'));   % load the sample eeglab epoched
dataset
EEG = pop_dipfit_settings( EEG, 'hdmfile',fullfile(bemPath,
'standard_vol.mat'), ...
           'coordformat','MNI','mrifile',fullfile(bemPath,
'standard_mri.mat'), ...
           'chanfile',fullfile(bemPath, 'elec', 'standard_1005.elc'), ...
           'coord_transform',[0.83215 -15.6287 2.4114 0.081214
0.00093739 -1.5732 1.1742 1.0601 1.1485] , ...
           'chansel',[1:32] );


%% Leadfield Matrix calculation
dataPre = eeglab2fieldtrip(EEG, 'preprocessing', 'dipfit');   %
convert the EEG data structure to fieldtrip

cfg = [];
cfg.channel = {'all', '-EOG1'};
cfg.reref = 'yes';
cfg.refchannel = {'all', '-EOG1'};
dataPre = ft_preprocessing(cfg, dataPre);

vol = load('-mat', EEG.dipfit.hdmfile);

cfg            = [];
cfg.elec       = dataPre.elec;
cfg.headmodel  = vol.vol;
cfg.resolution = 10;   % use a 3-D grid with a 1 cm resolution
cfg.unit       = 'mm';
cfg.channel    = { 'all' };
[sourcemodel] = ft_prepare_leadfield(cfg);

%% Compute an ERP in Fieldtrip. Note that the covariance matrix needs
to be calculated here for use in source estimation.
cfg                  = [];
cfg.covariance       = 'yes';
cfg.covariancewindow = [EEG.xmin 0]; % calculate the average of the
covariance matrices
                                   % for each trial (but using the
pre-event baseline  data only)
dataAvg = ft_timelockanalysis(cfg, dataPre);

% source reconstruction
cfg             = [];
cfg.method      = 'eloreta';
cfg.sourcemodel = sourcemodel;
cfg.headmodel   = vol.vol;
source          = ft_sourceanalysis(cfg, dataAvg);  % compute the source model

%% Plot Loreta solution
cfg = [];
cfg.projectmom = 'yes';
cfg.flipori = 'yes';
sourceProj = ft_sourcedescriptives(cfg, source);

cfg = [];
cfg.parameter = 'mom';
cfg.operation = 'abs';
sourceProj = ft_math(cfg, sourceProj);

cfg              = [];
cfg.method       = 'ortho';
cfg.funparameter = 'mom';
figure; ft_sourceplot(cfg, sourceProj);



%% project sources on MRI and plot solution
mri = load('-mat', EEG.dipfit.mrifile);
mri = ft_volumereslice([], mri.mri);

cfg              = [];
cfg.downsample   = 2;
cfg.parameter    = 'pow';
source.oridimord = 'pos';
source.momdimord = 'pos';
sourceInt  = ft_sourceinterpolate(cfg, source , mri);

cfg              = [];
cfg.method       = 'slice';
cfg.funparameter = 'pow';
ft_sourceplot(cfg, sourceInt);



%% Prepare leadfield surface
[ftVer, ftPath] = ft_version;
sourcemodel = ft_read_headshape(fullfile(ftPath, 'template',
'sourcemodel', 'cortex_8196.surf.gii'));

cfg           = [];
cfg.grid      = sourcemodel;    % source points
cfg.headmodel = vol.vol;        % volume conduction model
leadfield = ft_prepare_leadfield(cfg, dataAvg);


%% Surface source analysis
cfg               = [];
cfg.method        = 'mne';
cfg.grid          = leadfield;
cfg.headmodel     = vol.vol;
cfg.mne.lambda    = 3;
cfg.mne.scalesourcecov = 'yes';
source            = ft_sourceanalysis(cfg, dataAvg);


%% Surface source plot
cfg = [];
cfg.funparameter = 'pow';
cfg.maskparameter = 'pow';
cfg.method = 'surface';
cfg.latency = 0.4;
cfg.opacitylim = [0 200];
ft_sourceplot(cfg, source);

%%
hold on; ft_plot_mesh(vol.vol.bnd(3), 'facecolor', 'red', 'facealpha',
0.05, 'edgecolor', 'none');
hold on; ft_plot_mesh(vol.vol.bnd(2), 'facecolor', 'red', 'facealpha',
0.05, 'edgecolor', 'none');
hold on; ft_plot_mesh(vol.vol.bnd(1), 'facecolor', 'red', 'facealpha',
0.05, 'edgecolor', 'none');



More information about the eeglablist mailing list