<html><head></head><body><div class="yahoo-style-wrap" style="font-family:bookman old style, new york, times, serif;font-size:16px;"><div dir="ltr" data-setdir="false"><div><p class="ydp68493749MsoNormal">Dear all,</p>
<p class="ydp68493749MsoNormal">I am doing source analysis based on subject-specific MRI and
currently having an issue to do source grandaveraging. I tried to use different
version of fieldtrips (i.e. Fieldtrip-20181122, Fieldtrip-20191127 and
Fieltrip-20200109), and it still ended up with the same error: “Error using
ft_sourcegrandaverage (line 116) the input sources vary in the field inside”. I
also aware that this issue was discussed previously <a href="https://mailman.science.ru.nl/pipermail/fieldtrip/2015-October/022580.html" rel="nofollow" target="_blank">https://mailman.science.ru.nl/pipermail/fieldtrip/2015-October/022580.html</a>.
Unfortunately, I still facing the same error after specifying source.pos =
template_grid.pos. It would be grateful if some of you can help and let me know
my mistakes in the scripts below. It is a long script and I was thinking it
might be helpful to provide a full script for others to help. Hope to hear from
you guys soon. Thank you.</p>
<p class="ydp68493749MsoNormal">***********************************Forward
model************************************************************</p>
<p class="ydp68493749MsoNormal">subject_data= {'A’, ‘B’};</p>
<p class="ydp68493749MsoNormal">subj={'A’, ‘B’};</p>
<p class="ydp68493749MsoNormal">nsubj = numel(subject_data);</p>
<p class="ydp68493749MsoNormal">% MRI Segmentation</p>
<p class="ydp68493749MsoNormal">% if do_mri_seg</p>
<p class="ydp68493749MsoNormal">% read the *mgz files from FreeSurfer</p>
<p class="ydp68493749MsoNormal">fprintf(['starting forward model for: ', subj{s},'\n '])</p>
<p class="ydp68493749MsoNormal">mri = ft_read_mri([subject_mri, subj{s},'/','mri/','T1.mgz']);</p>
<p class="ydp68493749MsoNormal">mri.coordsys = 'ctf';</p>
<p class="ydp68493749MsoNormal">% interactively set fiducials to align MRI space to EEG
space</p>
<p class="ydp68493749MsoNormal">cfg = [];</p>
<p class="ydp68493749MsoNormal">cfg.method = 'interactive';</p>
<p class="ydp68493749MsoNormal">mri = ft_volumerealign(cfg, mri);</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">cfg
= [];</p>
<p class="ydp68493749MsoNormal">cfg.output = {'brain','skull','scalp'};</p>
<p class="ydp68493749MsoNormal">segmentedmri = ft_volumesegment(cfg, mri);</p>
<p class="ydp68493749MsoNormal">% save segmentedmri</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">%%</p>
<p class="ydp68493749MsoNormal">% Head mesh</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">%if do_head_mesh</p>
<p class="ydp68493749MsoNormal">addpath 'XXXXXX/fieldtrip-20181122/external/spm12'</p>
<p class="ydp68493749MsoNormal">segmentedmri.dim = segmentedmri.dim;</p>
<p class="ydp68493749MsoNormal">segmentedmri.coordsys = segmentedmri.coordsys;</p>
<p class="ydp68493749MsoNormal">segmentedmri.unit = segmentedmri.unit;</p>
<p class="ydp68493749MsoNormal">cfg = [];</p>
<p class="ydp68493749MsoNormal">cfg.tissue = {'brain','skull','scalp'};</p>
<p class="ydp68493749MsoNormal">cfg.method = 'projectmesh';</p>
<p class="ydp68493749MsoNormal">cfg.numvertices = [3000 2000 1000];</p>
<p class="ydp68493749MsoNormal">mri_bnd = [];</p>
<p class="ydp68493749MsoNormal">mri_bnd.transform = segmentedmri.transform;</p>
<p class="ydp68493749MsoNormal">mri_bnd.brain = segmentedmri.brain;</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">braindil = imdilate(segmentedmri.brain, strel_bol(6));</p>
<p class="ydp68493749MsoNormal">mri_bnd.skull = braindil > 0.5;</p>
<p class="ydp68493749MsoNormal">mri_bnd.scalp = segmentedmri.scalp;</p>
<p class="ydp68493749MsoNormal">mri_bnd.dim = segmentedmri.dim;</p>
<p class="ydp68493749MsoNormal">mri_bnd.coordsys = segmentedmri.coordsys;</p>
<p class="ydp68493749MsoNormal">mri_bnd.unit = segmentedmri.unit;</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">src = ft_prepare_mesh(cfg, mri_bnd);</p>
<p class="ydp68493749MsoNormal">% save src</p>
<p class="ydp68493749MsoNormal">%% </p>
<p class="ydp68493749MsoNormal">% COMPONENT 1: Headmodel </p>
<p class="ydp68493749MsoNormal">addpath 'XXX/fieldtrip-20181122/external/dipoli'</p>
<p class="ydp68493749MsoNormal">cfg = [];</p>
<p class="ydp68493749MsoNormal">cfg.method = 'dipoli';</p>
<p class="ydp68493749MsoNormal">hdm = ft_prepare_headmodel(cfg, src);</p>
<p class="ydp68493749MsoNormal">% save hdm </p>
<p class="ydp68493749MsoNormal">disp(hdm)</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">%%</p>
<p class="ydp68493749MsoNormal">% COMPONENT 2: Sensor
adjustment %
getting electrodes in the right position</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">%if do_sensor_alignment</p>
<p class="ydp68493749MsoNormal">sens = ft_read_sens([XXX, subj{s}, '.sfp']); %
GEOSCAN </p>
<p class="ydp68493749MsoNormal">sens = ft_convert_units(sens, 'mm');</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">nas = mri.cfg.fiducial.nas;</p>
<p class="ydp68493749MsoNormal">lpa = mri.cfg.fiducial.lpa;</p>
<p class="ydp68493749MsoNormal">rpa = mri.cfg.fiducial.rpa;</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">% warp NAS LPA and RPA</p>
<p class="ydp68493749MsoNormal">nas = ft_warp_apply(mri.transform, nas, 'homogenous');</p>
<p class="ydp68493749MsoNormal">lpa = ft_warp_apply(mri.transform, lpa, 'homogenous');</p>
<p class="ydp68493749MsoNormal">rpa = ft_warp_apply(mri.transform, rpa, 'homogenous');</p>
<p class="ydp68493749MsoNormal">fid = [];</p>
<p class="ydp68493749MsoNormal">fid.elecpos = [nas; lpa;
rpa]; % ctf-coordinates of fiducials</p>
<p class="ydp68493749MsoNormal">fid.chanpos = [nas; lpa;
rpa]; % ctf-coordinates of fiducials</p>
<p class="ydp68493749MsoNormal"><span lang="DE">fid.label
= {char(sens.label(1)); ...</span></p>
<p class="ydp68493749MsoNormal"><span lang="DE">
</span>char(sens.label(2)); ...</p>
<p class="ydp68493749MsoNormal">
char(sens.label(3))}; % same
labels as in elec</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">% alignment</p>
<p class="ydp68493749MsoNormal">cfg
= [];</p>
<p class="ydp68493749MsoNormal">cfg.method =
'fiducial';</p>
<p class="ydp68493749MsoNormal">cfg.target =
fid;
% see above</p>
<p class="ydp68493749MsoNormal">cfg.elec
= sens;</p>
<p class="ydp68493749MsoNormal">cfg.fiducial =
{char(sens.label(1)); ...</p>
<p class="ydp68493749MsoNormal">
char(sens.label(2)); ...</p>
<p class="ydp68493749MsoNormal">
char(sens.label(3))}; % labels of fiducials in fid and in
elec </p>
<p class="ydp68493749MsoNormal">elec_aligned =
ft_electroderealign(cfg);</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">cfg = [];</p>
<p class="ydp68493749MsoNormal">cfg.method = 'project';</p>
<p class="ydp68493749MsoNormal">cfg.elec = elec_aligned;</p>
<p class="ydp68493749MsoNormal">cfg.headshape = src(3);</p>
<p class="ydp68493749MsoNormal">elec_aligned = ft_electroderealign(cfg);</p>
<p class="ydp68493749MsoNormal">% save elec_aligned </p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">%% </p>
<p class="ydp68493749MsoNormal">%COMPONENT 3: Source
model </p>
<p class="ydp68493749MsoNormal">% % load a template grid</p>
<p class="ydp68493749MsoNormal">% NOTE: the path to the template file is user-specific</p>
<p class="ydp68493749MsoNormal">pathin ='XXX/matlab/toolbox/';</p>
<p class="ydp68493749MsoNormal">load(fullfile(pathin,
'fieldtrip-20200109/template/sourcemodel/standard_sourcemodel3d5mm'));</p>
<p class="ydp68493749MsoNormal">template = sourcemodel;</p>
<p class="ydp68493749MsoNormal">clear sourcemodel;</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">% create the subject specific grid, using the template grid
that has just been created</p>
<p class="ydp68493749MsoNormal">% inverse-warp the template grid to subject specific
coordinates</p>
<p class="ydp68493749MsoNormal">cfg = [];</p>
<p class="ydp68493749MsoNormal">cfg.warpmni = 'yes';</p>
<p class="ydp68493749MsoNormal">cfg.template = template;</p>
<p class="ydp68493749MsoNormal">cfg.nonlinear = 'yes';</p>
<p class="ydp68493749MsoNormal">cfg.mri = mri; %mri - not working properly/ showing
scalp</p>
<p class="ydp68493749MsoNormal">cfg.unit = 'mm';</p>
<p class="ydp68493749MsoNormal">grid =
ft_prepare_sourcemodel(cfg);</p>
<p class="ydp68493749MsoNormal">%save grid</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">%% </p>
<p class="ydp68493749MsoNormal">% COMPONENT 4: Leadfield</p>
<p class="ydp68493749MsoNormal">fname_preproc_data = fullfile(XXX,subject_data{s}]); </p>
<p class="ydp68493749MsoNormal">preproc_data = load(fname_preproc_data);</p>
<p class="ydp68493749MsoNormal">EEG_name = cell2mat(fieldnames(preproc_data));</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">% </p>
<p class="ydp68493749MsoNormal">cfg
= [];</p>
<p class="ydp68493749MsoNormal">cfg.elec
= elec_aligned;</p>
<p class="ydp68493749MsoNormal">cfg.channel
=
preproc_data.conv_data_rpost.label;
% ensure that rejected electrodes are not present</p>
<p class="ydp68493749MsoNormal">cfg.headmodel
= hdm;</p>
<p class="ydp68493749MsoNormal">cfg.grid.pos
= sourcemodel.pos;</p>
<p class="ydp68493749MsoNormal">cfg.normalize
=
'no';
%normalize 'yes' it when don't have a contrast to avaoid activity at the
center (NAI tutorial)</p>
<p class="ydp68493749MsoNormal">cfg.normalizeparam = 0.5;</p>
<p class="ydp68493749MsoNormal">cfg.grid.unit
= 'mm';</p>
<p class="ydp68493749MsoNormal">leadfield
= ft_prepare_leadfield(cfg);</p>
<p class="ydp68493749MsoNormal">%save leadfield</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> % the data consists of fewer channels than the
precomputed</p>
<p class="ydp68493749MsoNormal"> % leadfields, the following chunk of code
takes care of this</p>
<p class="ydp68493749MsoNormal">[a,b] = match_str(preproc_data.conv_data_rpost.label,
leadfield.label);</p>
<p class="ydp68493749MsoNormal">for k = 1:numel(leadfield.leadfield)</p>
<p class="ydp68493749MsoNormal"> if ~isempty(leadfield.leadfield{k})</p>
<p class="ydp68493749MsoNormal"> tmp =
leadfield.leadfield{k};</p>
<p class="ydp68493749MsoNormal"> tmp = tmp(b,:);</p>
<p class="ydp68493749MsoNormal"> tmp =
tmp-repmat(mean(tmp,1),[size(tmp,1) 1]); % average re-ref</p>
<p class="ydp68493749MsoNormal">
leadfield.leadfield{k} = tmp;</p>
<p class="ydp68493749MsoNormal"> end</p>
<p class="ydp68493749MsoNormal">end</p>
<p class="ydp68493749MsoNormal">leadfield.label = leadfield.label(b);</p>
<p class="ydp68493749MsoNormal">%save leadfield</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">*****************************************************source_analysis**************************************</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">subject_rpost_data= {‘A’, ‘B’}; </p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">subj={‘A’, ‘B’ };</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">nsubj = numel(subj);</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> % Loop over subjects</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> for s=1:nsubj</p>
<p class="ydp68493749MsoNormal"> fprintf(['starting source analysis for:
', subj{s},'\n '])</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> load(fname_preproc_data);</p>
<p class="ydp68493749MsoNormal"> load(fname_sourcemodel);</p>
<p class="ydp68493749MsoNormal"> load(fname_leadfield);</p>
<p class="ydp68493749MsoNormal"> load(fname_headmodel);</p>
<p class="ydp68493749MsoNormal"> load(fname_elec);</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> mri =
ft_read_mri(fname_seg_mri); </p>
<p class="ydp68493749MsoNormal"> mri.coordsys = 'ctf';</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> load(fname_smri ) </p>
<p class="ydp68493749MsoNormal"> % transform original mri to
segemented mri transformation info</p>
<p class="ydp68493749MsoNormal"> trns = segmentedmri.transform /
mri.transform;</p>
<p class="ydp68493749MsoNormal"> clear segmentedmri</p>
<p class="ydp68493749MsoNormal"> % reslice mri</p>
<p class="ydp68493749MsoNormal"> mri.coordsys = 'ctf';</p>
<p class="ydp68493749MsoNormal"> mri = ft_volumereslice([], mri);</p>
<p class="ydp68493749MsoNormal"> % transform mri to coordinates of
leadfield </p>
<p class="ydp68493749MsoNormal"> mri = ft_transform_geometry(trns,
mri);</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> % Bring data as in time domain</p>
<p class="ydp68493749MsoNormal"> % Cut Trial data in baseline and evoked
time segments</p>
<p class="ydp68493749MsoNormal"> cfg = [];</p>
<p class="ydp68493749MsoNormal"> cfg.latency = [-1.0 0]; %
baseline % choose baseline as i did
with sensor analysis (100ms)</p>
<p class="ydp68493749MsoNormal"> datbasl = ft_selectdata(cfg,
preproc_data.(EEG_name));</p>
<p class="ydp68493749MsoNormal"> cfg = [];</p>
<p class="ydp68493749MsoNormal"> cfg.latency = [0 3]; % evoked activity</p>
<p class="ydp68493749MsoNormal"> datact = ft_selectdata(cfg,preproc_data.(EEG_name));</p>
<p class="ydp68493749MsoNormal"> cfg = [];</p>
<p class="ydp68493749MsoNormal"> cfg.latency = [-1 3];</p>
<p class="ydp68493749MsoNormal"> datall =
ft_selectdata(cfg,preproc_data.(EEG_name));</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">%%
</p>
<p class="ydp68493749MsoNormal"> % Compute covariance matrix</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">
cfg = [];</p>
<p class="ydp68493749MsoNormal"> cfg.covariance = 'yes';</p>
<p class="ydp68493749MsoNormal"> cfg.keeptrials = 'no'; % 'no' creates
averaged trial</p>
<p class="ydp68493749MsoNormal"> cfg.removemean = 'yes';</p>
<p class="ydp68493749MsoNormal"> cfg.channel = {'all', '-E257'};</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> datbasl_avg =
ft_timelockanalysis(cfg, datbasl); %Baseline data (in time domain)</p>
<p class="ydp68493749MsoNormal"> datact_avg =
ft_timelockanalysis(cfg, datact); %Activity data</p>
<p class="ydp68493749MsoNormal"> datall_avg =
ft_timelockanalysis(cfg, datall); %Data with baseline and activity</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> %% Source analysis</p>
<p class="ydp68493749MsoNormal"> %</p>
<p class="ydp68493749MsoNormal"> % adapt leadfield channels to channel of
current eeg data (199 instead</p>
<p class="ydp68493749MsoNormal"> % of 256)</p>
<p class="ydp68493749MsoNormal"> [~,b] = match_str(datbasl_avg.label,
leadfield.label);</p>
<p class="ydp68493749MsoNormal"> for k = 1:numel(leadfield.leadfield)</p>
<p class="ydp68493749MsoNormal"> if
~isempty(leadfield.leadfield{k})</p>
<p class="ydp68493749MsoNormal">
tmp = leadfield.leadfield{k};</p>
<p class="ydp68493749MsoNormal">
tmp = tmp(b,:);</p>
<p class="ydp68493749MsoNormal">
tmp = tmp-repmat(mean(tmp,1),[size(tmp,1) 1]); % average re-ref</p>
<p class="ydp68493749MsoNormal">
leadfield.leadfield{k} = tmp;</p>
<p class="ydp68493749MsoNormal"> end</p>
<p class="ydp68493749MsoNormal"> end</p>
<p class="ydp68493749MsoNormal"> leadfield.label = leadfield.label(b);</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> % Compute common spatial
filter </p>
<p class="ydp68493749MsoNormal"> cfg
= [];</p>
<p class="ydp68493749MsoNormal">
cfg.channel =
datall_avg.label;</p>
<p class="ydp68493749MsoNormal">
cfg.elec
= elec_aligned.elec_aligned;</p>
<p class="ydp68493749MsoNormal">
cfg.method =
'lcmv';</p>
<p class="ydp68493749MsoNormal">%
cfg.grid =
leadfield;</p>
<p class="ydp68493749MsoNormal">
cfg.headmodel = headmodel.hdm;</p>
<p class="ydp68493749MsoNormal"> cfg.sourcemodel.grid.pos =
leadfield.pos; % bei FT wird hier der output von ft_leadfield angegeben </p>
<p class="ydp68493749MsoNormal"> cfg.grid.resolution = 5;</p>
<p class="ydp68493749MsoNormal"> cfg.lcmv.keepfilter = 'yes';</p>
<p class="ydp68493749MsoNormal"> cfg.lcmv.fixedori
= 'yes';</p>
<p class="ydp68493749MsoNormal"> cfg.lcmv.projectnoise = 'yes';</p>
<p class="ydp68493749MsoNormal"> cfg.lcmv.weightnorm = 'nai';</p>
<p class="ydp68493749MsoNormal">
cfg.lcmv.lambda = '5%';</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> eegsrc_all = ft_sourceanalysis(cfg,
datall_avg); %source data in all time window</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> % apply common filters to pre and
post stimulus data</p>
<p class="ydp68493749MsoNormal">
cfg.grid.filter = eegsrc_all.avg.filter;</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> % Compute source for baseline and
activty time window</p>
<p class="ydp68493749MsoNormal"> eegsrc_basl = ft_sourceanalysis(cfg,
datbasl_avg); %source data for baseline time window</p>
<p class="ydp68493749MsoNormal"> eegsrc_act = ft_sourceanalysis(cfg,
datact_avg); %source data for activity time window</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> % contrast post stimulus onset
activity with respect to baseline</p>
<p class="ydp68493749MsoNormal"> eegsrc_act_basnrm = eegsrc_act;</p>
<p class="ydp68493749MsoNormal"> eegsrc_act_basnrm.avg.pow =
(eegsrc_act.avg.pow - eegsrc_basl.avg.pow)./ eegsrc_basl.avg.pow;</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> %% Choose time of interest</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> % average across time the dipole moments
within the N1 latency range</p>
<p class="ydp68493749MsoNormal"> ind =
find(eegsrc_act_basnrm.time>=0.1 & eegsrc_act_basnrm.time<=0.5); %at
18ms-24ms</p>
<p class="ydp68493749MsoNormal"> timecourse =
eegsrc_act_basnrm.avg.mom(eegsrc_act_basnrm.inside);</p>
<p class="ydp68493749MsoNormal"> tc_toi =
zeros(size(eegsrc_act_basnrm.avg.pow(eegsrc_act_basnrm.inside)));</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> for ii = 1:length(timecourse)</p>
<p class="ydp68493749MsoNormal"> tc_toi(ii) =
mean(abs(timecourse{ii}(ind)));</p>
<p class="ydp68493749MsoNormal"> end</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> source = eegsrc_act_basnrm;</p>
<p class="ydp68493749MsoNormal"> source.avg.pow(eegsrc_act_basnrm.inside)
= tc_toi;</p>
<p class="ydp68493749MsoNormal">% source.cfg = rmfield(source.cfg,
{'headmodel' 'callinfo'}); % this is removed because it takes up a lot of
memory</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> % Save source</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> % interpolate and normalize to
individual mri</p>
<p class="ydp68493749MsoNormal"> %first, interpolate</p>
<p class="ydp68493749MsoNormal">
cfg = [];</p>
<p class="ydp68493749MsoNormal"> cfg.parameter = 'pow';</p>
<p class="ydp68493749MsoNormal"> eeg_source_interp =
ft_sourceinterpolate(cfg, source, mri);</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> % second, normalise</p>
<p class="ydp68493749MsoNormal"> cfg = [];</p>
<p class="ydp68493749MsoNormal"> cfg.nonlinear =
'no';</p>
<p class="ydp68493749MsoNormal"> eeg_source_interp_norm =
ft_volumenormalise(cfg, eeg_source_interp);</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> % save the interpolate and
normalised data </p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">%% </p>
<p class="ydp68493749MsoNormal"> % load source
reconstructed data</p>
<p class="ydp68493749MsoNormal">% keep subjects path_data nsubj
path_ft</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> allsource_rpost = cell(1,nsubj);</p>
<p class="ydp68493749MsoNormal"> for s = 1:nsubj</p>
<p class="ydp68493749MsoNormal"> datapath =
strcat(fname_eeg_source_interp_norm);</p>
<p class="ydp68493749MsoNormal">% datafile =
fullfile(datapath, [subj{s}, '_source.mat']); % take _source
data?</p>
<p class="ydp68493749MsoNormal"> datafile =
fullfile(datapath, [subj{s}, '_eeg_source_interp_norm.mat']); </p>
<p class="ydp68493749MsoNormal"> load(datafile)</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">
allsource_rpost{s} = eeg_source_interp_norm;</p>
<p class="ydp68493749MsoNormal">%
allsource_rpost{s} = source;</p>
<p class="ydp68493749MsoNormal"> end</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> % grand average</p>
<p class="ydp68493749MsoNormal">
cfg =
[];</p>
<p class="ydp68493749MsoNormal"> cfg.parameter = 'pow';</p>
<p class="ydp68493749MsoNormal">% cfg.keepindividual='yes';</p>
<p class="ydp68493749MsoNormal"> gasource_rpost =
ft_sourcegrandaverage(cfg, allsource_rpost{:});</p>
<p class="ydp68493749MsoNormal"> %save gasource_rpost</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">With best wishes,</p>
<p class="ydp68493749MsoNormal">Faizal Zulkifly</p>
<p class="ydp68493749MsoNormal"> </p>
<p class="ydp68493749MsoNormal">--------------------------------------------------------</p>
<p class="ydp68493749MsoNormal">Mohd Faizal Mohd Zulkifly</p>
<p class="ydp68493749MsoNormal">University Medical Center Göttingen</p>
<p class="ydp68493749MsoNormal">University of Göttingen</p>
<p class="ydp68493749MsoNormal">Clinic for Clinical Neurophysiology</p>
<p class="ydp68493749MsoNormal"><span lang="DE">Robert-Koch-Straße
40</span></p>
<p class="ydp68493749MsoNormal"><span lang="DE">37075 Göttingen</span></p>
<p class="ydp68493749MsoNormal"><span lang="DE">Germany</span></p>
<p class="ydp68493749MsoNormal"><span lang="DE">Tel: +49 551
39-8457</span></p>
<p class="ydp68493749MsoNormal"><span lang="DE"> </span></p></div><br></div></div></body></html>