<div dir="ltr"><div><div><div>Hi all,<br><br></div>I have a pipeline created where at the ft_prepare_leadfield step, the grid.label and cfg.channel fields both exist, But when I run the ft_sourceanalysis, they result as empty matrices--throwing an error.<br><br></div><div>they are both cells {128x1}, but at ft_sourceanalysis result in [ ]<br></div><div><br></div>here is my code for reference. Sorry for the long post, I am very close to a deadline and would be very grateful for your help. Please scroll below to see section where the error is thrown.<br><br><b>%% parameters list</b> (just for reference)<br>mrifile='Siemens_AF8-MPRAGE_20141022_1.nii';<br>mritype='MNI';<br>realign='realigned';<br>volumereslicing='volumeresliced';<br>brainthresh=0.5;<br>scalpthresh=0.10;<br>scalpsmooth='scalp_smooth';<br>scalp_smooth.parameter=9;<br>scalpvertices=1000;<br>skullvertices=1000;<br>brainvertices=1000;<br>meshmethod='projectmesh';<br>headmodel_method='bemcp';<br>subjnum='915';<br>time='pre';<br>timetype='simple';<br>gridtype='template10';<br>beamformer='lcmv';<br>identifier='Parameter2';<br><br><b>%% make headmodel</b><br>switch mritype<br>    case 'MNI'<br>        [mri]               = ft_read_mri(mrifile);<br>        mri.coordsys        ='MNI';<br>    case 'Analyze'<br>        [mri]               = ft_read_mri(mrifile);<br>        mri.coordsys        ='Analyze';<br>end<br><b><br>%% realigning</b><br>switch realign<br>    case 'realigned'<br>        cfg=[];<br>        cfg.method='fiducial';<br>        cfg.fiducial.nas    = [6.60688      6.30230     -2.94229];<br>        cfg.fiducial.lpa    = [6.04082      7.65872     0.350950];<br>        cfg.fiducial.rpa    = [4.41106      8.71481      3.50199];<br>        mri_realigned=ft_volumerealign(cfg,mri);<br>        save(strcat(mrifile,'_',identifier,'_','mri_realigned.mat'),'mri_realigned')<br>    case 'notrealigned'<br>        %do nothing<br>end<br><br><b>%% volume reslicing</b><br>switch volumereslicing<br>    case 'volumeresliced'<br>    cfg = [];<br>    cfg.resolution = 1;<br>    mri_resliced = ft_volumereslice(cfg, mri);<br>    save(strcat(mrifile,'_',identifier,'_','mri_resliced.mat'),'mri_resliced')<br>    case 'notresliced'<br>        %do nothing<br>end<br><br><b>%% segmentation parameters</b><br>switch scalpsmooth<br>    case 'noscalpsmooth'<br>        cfg                 = [];<br>        cfg.brainthreshold  = braintresh;<br>        cfg.scalpthreshold  = scalpthresh;<br>        cfg.downsample      = 1; %no downsampling<br>        cfg.output          = {'brain' 'skull' 'scalp'};<br>        seg                 = ft_volumesegment(cfg, mri);<br>    case 'scalp_smooth'<br>        cfg                 = [];<br>        cfg.brainthreshold  = brainthresh;<br>        cfg.scalpthreshold  = scalpthresh;<br>        cfg.scalpsmooth     = scalp_smooth.parameter;<br>        cfg.downsample      = 1; %no downsampling<br>        cfg.output          = {'brain' 'skull' 'scalp'};<br>        seg                 = ft_volumesegment(cfg, mri); <br>end<br><br><b>%%prepare mesh </b><br><br>cfg                 = [];<br>cfg.method= meshmethod;<br>cfg.tissue          = {'scalp', 'skull', 'brain'};<br>cfg.numvertices     = [scalpvertices skullvertices brainvertices];<br>bnd                 = ft_prepare_mesh(cfg, seg);<br>% i enlarged / reduced the boundary mesh a little bit, because they were causing errors, probably due to overlapping<br>bnd(1).pnt          = bnd(1).pnt.*1.001;<br>bnd(2).pnt          = bnd(2).pnt.*1;<br>bnd(3).pnt          = bnd(3).pnt.*0.999;<br><br><br></div><b>%% prepare headmodel</b><br><div>switch headmodel_method<br>    case 'dipoli'<br>        cfg                 = [];<br>        cfg.method          = 'dipoli';<br>    case 'bemcp'<br>        cfg                 = [];<br>        cfg.method          = 'bemcp';<br>end<br><br>headmodel           = ft_prepare_headmodel(cfg, bnd);<br>headmodel           = ft_convert_units(headmodel,'cm');<br><br><b>%% adding electrodes to headmodel</b><br>elec=ft_read_sens('Hydrocel_GSN_128_1.0_TRIM_mod.sfp');    %load electrode file                     <br>% visualize head surface (scalp)<br>figure;<br>ft_plot_mesh(headmodel.bnd(1), 'edgecolor','none','facealpha',0.8,'facecolor',[0.6 0.6 0.8]); <br>hold on;<br>% plot electrodes<br>ft_plot_sens(elec,'style', 'sk')<br><br>%most likely they are not aligned, so for aligning electrodes<br>cfg           = [];<br>cfg.method    = 'interactive';<br>cfg.elec      = elec;<br>cfg.headshape = headmodel.bnd(1);%scalp<br>elec_aligned  = ft_electroderealign(cfg);%use the gui to manually align the electrodes<br>nas=mri_realigned.cfg.fiducial.nas;<br>lpa=mri_realigned.cfg.fiducial.lpa;<br>rpa=mri_realigned.cfg.fiducial.rpa;<br><b><br>%% load EEG data</b><br><br></div><div>i can send these to any ambitiously nice person wanting to try out the script exactly<br><br><b>%% timelock data</b><br><br><br>elec=ft_read_sens('Hydrocel_GSN_128_1.0_TRIM_mod.sfp');<br><br>cfg = [];<br>    same = dataM0;<br>    same.trial = [dataM0.trial dataM3W.trial];<br>    same.time = [dataM0.time dataM3W.time];<br>    <br>    diff = dataM6;<br>    diff.trial = [dataM3Bb.trial dataM6.trial];<br>    diff.time = [dataM3Bb.time dataM6.time];<br>    <br> switch timetype<br>     case 'simple'<br>        timelock_m0 = ft_timelockanalysis(cfg, dataM0);<br>        timelock_m6 = ft_timelockanalysis(cfg, dataM6);<br>        timelock_m3w = ft_timelockanalysis(cfg, dataM3W);<br>        timelock_m3b = ft_timelockanalysis(cfg, dataM3Bb);<br>        timelock_diff = ft_timelockanalysis(cfg, diff);<br>        timelock_same = ft_timelockanalysis(cfg, same);<br>     case 'hassan'<br>       cfg.vartrllength = 2;<br>       cfg.covariance = 'yes';<br>       cfg.covariancewindow = [0 .2];<br>       cfg.keeptrials = 'yes';<br>       timelock_m0 = ft_timelockanalysis(cfg, dataM0);<br>       timelock_m6 = ft_timelockanalysis(cfg, dataM6);<br>       timelock_m3w = ft_timelockanalysis(cfg, dataM3W);<br>       timelock_m3b = ft_timelockanalysis(cfg, dataM3Bb);<br>       timelock_diff = ft_timelockanalysis(cfg, diff);<br>       timelock_same = ft_timelockanalysis(cfg, same);<br><br><b><br>%% make sourcemodel</b><br>cfg = [];<br>cfg.headmodel = headmodel;<br>cfg.mri=mri;<br>cfg.grid.warpmni = 'yes';<br>cfg.grid.template = sourcemodel.cfg.grid;<br>cfg.grid.nonlinear = 'yes';<br>cfg.resolution = 10; % resolution of the template grid in mm<br>cfg.moveinward = 1; <br>cfg.grid.unit      ='mm';<br>cfg.inwardshift = 0; <br>cfg.elec = elec;<br>% cfg.headshape=('cortex_5124.surf.gii');<br>mysourcemodel = ft_prepare_sourcemodel(cfg);<br><b><br>%% make leadfield</b><br>switch gridtype<br>    case 'individual'<br>        cfg            = [];<br>        cfg.elec       = elec;<br>        cfg.headmodel  = headmodel;<br>        cfg.grid       =mysourcemodel;<br>%         cfg.grid.resolution = 2; %gives me Error using ft_prepare_sourcemodel (line 163)<br>%You cannot specify cfg.grid.resolution and an explicit cfg.grid.xgrid simultaneously<br>        cfg.reducerank= 3;<br>        cfg.channel = elec.chanpos;<br>        cfg.grid.unit = 'cm';% same unit as above, i.e. in cm<br>        [grid] = ft_prepare_leadfield(cfg);<br>    case 'templatebased'<br>        load('standard_sourcemodel3d10mm.mat')<br>        cfg                 = [];<br>        cfg.elec            = elec;<br>        cfg.template = sourcemodel.cfg.grid;<br>        cfg.grid=grid;<br>        cfg.headmodel             = headmodel;<br>        cfg.reducerank      = 3; % default is 3 for EEG, 2 for MEG<br>        cfg.channel  = 'all';<br>        cfg.grid.unit       = 'cm';<br>        cfg.grid.tight      = 'yes';<br>        [grid] = ft_prepare_leadfield(cfg);<br>    case 'template10'<br>        load('standard_sourcemodel3d10mm.mat')<br>        [grid]=sourcemodel.cfg.grid;<br>end<br><b><br>%% run beamformer</b>-<b> <u>this step is what gives the error, </u></b><br><br>switch beamformer<br>    case 'lcmv'<br>        cfg = [];<br>        cfg.method = 'lcmv';<br>        cfg.elec=elec;<br>        cfg.lcmv.lambda='5%';<br>        cfg.grid = grid;<br>        cfg.headmodel = headmodel;<br>        cfg.lcmv.keepfilter = 'yes';<br>        cfg.lcmv.projectnoise='yes'; <br>        cfg.lcmv.fixedori = 'yes'; % project on axis of most variance using SVD<br><br><br>>>>>>the error is>>><br> <i>Subscript indices must either be real positive integers or logicals.<br><br>Error in beamformer_lcmv (line 168)<br>    noise = noise(end);<br><br>Error in ft_sourceanalysis (line 841)<br>dip(i) = beamformer_lcmv(grid, sens, headmodel, squeeze_avg, squeeze(Cy(i,:,:)), optarg{:});</i><br><u><b><br></b></u></div><div><u><b>I suspect its because in ft_sourceanalysis (line813) [i1, i2] = match_str(cfg.channel, grid.label)<br><br></b></u></div><div><u><b>the result is i1=[] and i2=[]. eventhough when I look up cfg.channel and grid.label in my variables they exist. after running ft_sourceanalysis the cfg.channel field disappeaers. </b></u><br></div><div><br></div><div><b>%%interpolate</b><br></div><div>cfg = [];<br>cfg.interpmethod = 'nearest';<br>cfg.parameter = 'pow';<br>sourceinterp_diff = ft_sourceinterpolate(cfg, sourceanalysis_diff, mri_resliced);<br>sourceinterp_m0 = ft_sourceinterpolate(cfg, sourceanalysis_m0, mri_resliced);<br>sourceinterp_m6 = ft_sourceinterpolate(cfg, sourceanalysis_m6, mri_resliced);<br>sourceinterp_m3w = ft_sourceinterpolate(cfg, sourceanalysis_m3w, mri_resliced);<br>sourceinterp_m3b = ft_sourceinterpolate(cfg, sourceanalysis_m3b, mri_resliced);<br>sourceinterp_same = ft_sourceinterpolate(cfg, sourceanalysis_same, mri_resliced);<br><br><b>%%Plot</b><br>cfg = [];<br>cfg.method            = 'surface';<br>cfg.funcolormap = 'jet';<br>% cfg.method        = 'ortho';<br>cfg.funcolorlim   = 'maxabs';<br>cfg.funparameter= 'pow';<br>ft_sourceplot(cfg,sourceinterp_diff);<br>ft_sourceplot(cfg,sourceinterp_m0);<br>ft_sourceplot(cfg,sourceinterp_m6);<br>ft_sourceplot(cfg,sourceinterp_m3w);<br>ft_sourceplot(cfg,sourceinterp_m3b);<br>ft_sourceplot(cfg,sourceinterp_same);<br></div></div>