<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p>Dear Fieldtrip experts, </p>
<p><br>
</p>
<p>I am currently trying to carry out source localization of EEG oscillations of a dataset. Although computation of leadfields of some participants seems fine, the computations of most participants generate only NaNs in leadfield matrices. I took a look at
the previous messages and saw that many researchers also experienced the same problem, but could not find any relevant solution. </p>
<p><br>
</p>
<p>I would really appreciate it, if the experts with more experience on it could guide me to solve this problem.</p>
<p><br>
</p>
<p>Here is the code I currently use. </p>
<p><br>
</p>
<p></p>
<div>ft_defaults;</div>
<div>mri = ft_read_mri('f73.nii');</div>
<div><br>
</div>
<div>ft_determine_coordsys(mri)</div>
<div>cfg = [];</div>
<div>cfg.method = 'interactive'</div>
<div>[mri] = ft_volumerealign(cfg, mri);</div>
<div>save mri mri</div>
<div><br>
</div>
<div><br>
</div>
<div><span style="font-size: 12pt;">cfg = [];</span><br>
</div>
<div>cfg.output = {'brain','skull','scalp'};</div>
<div>cfg.scalpthreshold = 0.05;</div>
<div><span style="font-size: 12pt;">segmentedmri = ft_volumesegment(cfg, mri);</span><br>
</div>
<div>save segmentedmri segmentedmri</div>
<div><br>
</div>
<div><span style="font-size: 12pt;">cfg = [];</span><br>
</div>
<div>cfg.tissue = {'brain','skull','scalp'};</div>
<div>cfg.numvertices = [3000 2000 1000];</div>
<div>bnd = ft_prepare_mesh(cfg,segmentedmri);</div>
<div>save bnd bnd</div>
<div></div>
<div><br>
</div>
<div>cfg = [];</div>
<div>cfg.method = 'bemcp'; </div>
<div>vol = ft_prepare_headmodel(cfg, bnd);</div>
<div>save vol vol</div>
<div><br>
</div>
<div>cfg = [];</div>
<div>cfg.tissue = 'scalp';</div>
<div>cfg.numvertices = 10000;</div>
<div>scalp = ft_prepare_mesh(cfg, segmentedmri);</div>
<div>save scalp scalp</div>
<div></div>
<div><br>
</div>
<div>%get elec info</div>
<div>load(fullfile(current_dir,'elec_template.mat'));</div>
<div>elec = ft_determine_coordsys(elec)</div>
<div></div>
<div><br>
</div>
<div>% markerpos = table2cell(readtable(['load(fullfile('C:\Users\......',['elec_template.mat']));marker_positions_' subj '.csv']));</div>
<div>% markerpos = table2cell(readtable(['marker_positions_P30.csv']));</div>
<div>markerpos = table2cell(readtable(['D:......\',[subj '.csv']]));</div>
<div>%%% align the electrodes %%%</div>
<div>for i = 1:length(markerpos)</div>
<div> elec.label{i} = char(markerpos{i,2});</div>
<div> elec.elecpos(i,:) = cell2mat(markerpos(i,3:5));</div>
<div> elec.chanunit{i} = 'V';</div>
<div> elec.chantype{i} = 'eeg';</div>
<div>end</div>
<div>elec.chanpos = elec.elecpos;</div>
<div><br>
</div>
<div></div>
<div><br>
</div>
<div>nas = mri.cfg.fiducial.nas;</div>
<div>lpa = mri.cfg.fiducial.lpa;</div>
<div>rpa = mri.cfg.fiducial.rpa;</div>
<div><br>
</div>
<div>transm = mri.transform;</div>
<div><br>
</div>
<div>nas = ft_warp_apply(transm,nas, 'homogenous');</div>
<div>lpa = ft_warp_apply(transm,lpa, 'homogenous');</div>
<div>rpa = ft_warp_apply(transm,rpa, 'homogenous');</div>
<div><br>
</div>
<div>% create a structure similar to a template set of electrodes</div>
<div>fid.elecpos = [nas; lpa; rpa]; % ctf-coordinates of fiducials</div>
<div>fid.label = {'nasion','Left Tragus','Right Tragus'}; % same labels as in elec</div>
<div>fid.unit = 'mm'; % same units as mri</div>
<div><br>
</div>
<div>% alignment</div>
<div>cfg = [];</div>
<div>cfg.method = 'fiducial';</div>
<div><span style="font-size: 12pt;">cfg.target = fid; % see above</span><br>
</div>
<div>cfg.elec = elec;</div>
<div>cfg.headshape = vol; %scalp</div>
<div>cfg.fiducial = {'nasion','Left Tragus','Right Tragus'}; % labels of fiducials in fid and in elec</div>
<div>elec_aligned = ft_electroderealign(cfg);</div>
<div></div>
<div><br>
</div>
<div>cfg = [];</div>
<div>cfg.method = 'interactive';</div>
<div>cfg.elec = elec_aligned;</div>
<div>cfg.headshape = vol.bnd(3);</div>
<div>elec_aligned = ft_electroderealign(cfg);</div>
<div><br>
</div>
<div>save elec_aligned elec_aligned</div>
<div><br>
</div>
<div>% Create the sourcemodel</div>
<div>cfg = [];</div>
<div>cfg.resolution = 7.5;</div>
<div>cfg.threshold = 0.1;</div>
<div>cfg.smooth = 5;</div>
<div>cfg.headmodel = vol;</div>
<div><span style="font-size: 12pt;">sourcemodel = ft_prepare_sourcemodel(cfg);</span><br>
</div>
<div><br>
</div>
<div>% Compute the leadfield</div>
<div>cfg = [];</div>
<div>cfg.sourcemodel = sourcemodel;</div>
<div>cfg.headmodel = vol;</div>
<div>cfg.elec = elec_aligned;</div>
<div></div>
<div>cfg.channel = {'all','-AFz','-M1','-M2','-nasion','-Left Eye','-Right Eye','-Left Tragus','-Right Tragus','-nose tip','-chin tip'};</div>
<div>cfg.reducerank = 3;</div>
<div>grid = ft_prepare_leadfield(cfg);</div>
<div><br>
</div>
<div>
<div style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
Thanks in advance,</div>
<div style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
Andac Topkan</div>
<div style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
University of Leipzig</div>
<br>
</div>
<p></p>
</div>
</body>
</html>