<div dir="ltr">Dear Andac Topkan,<br><br>I came across your query regarding the computation of leadfields resulting in NaNs for most participants. While I am not an expert in leadfield computation myself, I recall encountering a similar discussion that might shed some light on the issue.<br><br>It has been noted that using the 'bemcp' method for leadfield computation could potentially lead to the generation of NaNs due to inherent algorithmic characteristics. A commonly suggested workaround is to explore alternative methods. For instance, the 'dipoli' method is highly recommended, albeit with the caveat that it requires a Linux environment and administrator permissions to run successfully.<br><br>Alternatively, the 'openmeeg' method presents another viable option, compatible with Windows systems. However, it's worth mentioning that setting up 'openmeeg' can be somewhat complex, and the available documentation might not provide the clarity needed for a straightforward installation.<br><br>If these methods do not offer a viable solution, you might consider utilizing Brainstorm. Brainstorm is known for its user-friendly, visual, and automated approach to source modeling, which could potentially circumvent the problem you're facing.<br><br>I hope this information proves helpful. <div><br>Best wishes in your research endeavors,<br><br>Chengyuan Wu<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Topkan, Tugberk via fieldtrip <<a href="mailto:fieldtrip@science.ru.nl">fieldtrip@science.ru.nl</a>> 于2024年2月18日周日 13:44写道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg-3914343493346979963">




<div dir="ltr">
<div id="m_-3914343493346979963divtagdefaultwrapper" style="font-size:12pt;color:rgb(0,0,0);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>
</div>

_______________________________________________<br>
fieldtrip mailing list<br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" rel="noreferrer" target="_blank">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br>
<a href="https://doi.org/10.1371/journal.pcbi.1002202" rel="noreferrer" target="_blank">https://doi.org/10.1371/journal.pcbi.1002202</a><br>
</div></blockquote></div>