Thanks Jim,<br><br>That was exactly what was wrong. Sorry for the delayed response. I mistakenly thought that the leadfield function would create a grid (which it can, but I forgot to put in a cfg.resolution). <br><br><div class="gmail_quote">
On Fri, Mar 15, 2013 at 4:01 AM, Herring, J.D. (Jim) <span dir="ltr"><<a href="mailto:j.herring@fcdonders.ru.nl" target="_blank">j.herring@fcdonders.ru.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div link="blue" vlink="purple" lang="EN-US"><div><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Hi Russ,<u></u><u></u></span></p><p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I ran into a similar error which was avoided by following the steps in the <u>extended</u> beamformer tutorial (<a href="http://fieldtrip.fcdonders.nl/tutorial/beamformingextended" target="_blank">http://fieldtrip.fcdonders.nl/tutorial/beamformingextended</a>). The problem seems to rather be that ft_sourceinterpolate wrongly detects your functional data as being 2 dimensional (if I remember correctly) because a .dim field is not present. I did not have the time yet to find-out if it is a problem with the other beamformer tutorial or an actual bug.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">In any case, if I compare the steps in the extended beamformer tutorial with the steps you took I noticed that in the extended beamformer tutorial a sourcemodel (ft_prepare_sourcemodel) is calculated after calculating the headmodel, which is then used to calculate the leadfield (ft_prepare_leadfield), followed by using this leadfield in ft_sourceanalysis. Could you try and see if that works? <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Best,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Jim<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> <a href="mailto:fieldtrip-bounces@science.ru.nl" target="_blank">fieldtrip-bounces@science.ru.nl</a> [mailto:<a href="mailto:fieldtrip-bounces@science.ru.nl" target="_blank">fieldtrip-bounces@science.ru.nl</a>] <b>On Behalf Of </b>Russell G Port<br>
<b>Sent:</b> vrijdag 15 maart 2013 0:18<br><b>To:</b> FieldTrip discussion list<br><b>Subject:</b> [FieldTrip] Inner matrix mismatch in source interpolate<u></u><u></u></span></p></div><div><div class="h5"><p class="MsoNormal">
<u></u> <u></u></p><p class="MsoNormal">Hi Fieldtrippers,<u></u><u></u></p><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">When running ft source interpolate on my CTF MEG data, I get an error where it reaches line 237; tmp    = interpmat*tmp. The error is an inner matrix dimension mismatch. Here interpmat is  a 16777216(256x256x256) x642 matrix, (mri voxels X leaderfield interpolation matrix). tmp is a 1 * 642 matrix of power at the leaderfield coordinates. If this is just matrix math, then I assume the problem is just that the matrix have to be mxn and nxp. Is there any reason I cannot just use tmp=tmp' to make the inner dimensions match?<u></u><u></u></p>
</div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">Cheers Russ<u></u><u></u></p></div><div><p class="MsoNormal" style="margin-bottom:12.0pt"><u></u> <u></u></p><div><p class="MsoNormal" style="margin-bottom:12.0pt">
---------- Forwarded message ----------<br>From: <b>Russell G Port</b> <<a href="mailto:russgport@gmail.com" target="_blank">russgport@gmail.com</a>><br>Date: Sat, Mar 9, 2013 at 8:38 PM<br>Subject: source interpolate - tmp = interpmat*tmp; inner matrix must agree<br>
To: FieldTrip discussion list <<a href="mailto:fieldtrip@science.ru.nl" target="_blank">fieldtrip@science.ru.nl</a>><br><br><br>Hi Fieldtrippers,<br><br>I have a slight issue that I was hoping someone can help with. I have some CTF data, that I was trying to perform DICS beamforming and then source interpolation on. I am trying to beamform to the source of gamma frequency in the right hemisphere, comparing pre and post stimuli.  Heres the basic script:<br>
<br><b>People can skip the first part of code, I included it as possibly useful information for this plead <br></b><br>%%%%% Data has already been preprocessed and timelocked%%%%%%<br><br>     load('processed_data_500Hz.mat')<br>
     load('timelock_data_500Hz.mat')<br><br>%%%% following the beamforming tutorial %%%%%%%<br><br>%%%%%%%%%%%%%split and combine%%%%%%%%%%%%%  <br>     <br>    cfg        = [];                                           <br>
    cfg.toilim = baseline;  <br>    cfg.channel=channel<br>    total_bsl   = ft_redefinetrial(cfg, data);<br>      <br>    <br>    cfg        = [];                                           <br>    cfg.toilim = interest;                       <br>
    cfg.channel=channel<br>    total_interest   = ft_redefinetrial(cfg, data);<br>    <br>    cfg      = [];<br>    total_cmb = ft_appenddata(cfg, total_bsl, total_interest);<br>     <br>    total_cmb.trialinfo = [zeros(length(total_bsl.trial), 1); ones(length(total_interest.trial), 1)];<br>
<br><br>    %%%%%%%%%%%%%cross spectrial density for dics and tf for common filter%%%%%%%%%%%%%%<br>    <br>cfg = [];<br>cfg.method    = 'mtmfft';<br>cfg.output    = 'powandcsd';<br>cfg.tapsmofrq = 25;<br>
cfg.foilim    = 55;<br>freqPre_total = ft_freqanalysis(cfg, total_bsl);<br><br>cfg = [];<br>cfg.method    = 'mtmfft';<br>cfg.output    = 'powandcsd';<br>cfg.tapsmofrq = 25;<br>cfg.foilim    = 55;<br>freqPost_total = ft_freqanalysis(cfg, total_interest);<br>
<br>cfg = [];<br>cfg.method    = 'mtmfft';<br>cfg.output    = 'powandcsd';<br>cfg.tapsmofrq = 25;<br>cfg.foilim    = 55;<br>freqALL_total = ft_freqanalysis(cfg, total_cmb);<br><br><br>%%%%%%%%%%%%%%%%%%%%%%%% calc leadfield %%%%%%%%%%%%%%%%%%%%%%%%%%%<br>
<br>% <br>T=ft_read_mri('R128_V2.mri')<br><br>       cfg.fiducial.nas  = T.hdr.fiducial.mri.nas<br>    cfg.fiducial.lpa  = T.hdr.fiducial.mri.lpa<br>    cfg.fiducial.rpa  = T.hdr.fiducial.mri.rpa<br>    cfg.method         = 'fiducial'<br>
    cfg.coordsys       = 'ctf' <br>   <br>    [mri] = ft_volumerealign(cfg, T)<br> <br>cfg          = [];<br>cfg.coordsys = 'ctf'; % the MRI is expressed in the CTF coordinate system, see below<br>segmentedmri = ft_volumesegment(cfg, mri);<br>
<br>cfg        = [];<br>cfg.method = 'singleshell';<br>hdm        = ft_prepare_headmodel(cfg, segmentedmri);<br><br> vol = ft_convert_units(hdm, 'cm');<br><br>%%%%%%%%%%%%%%%<br><br><br>cfg                 = [];<br>
cfg.grad            = freqPost_total.grad;<br>cfg.vol          = vol;<br>cfg.reducerank      = 2;<br>cfg.channel         = 'MR'<br>[grid] = ft_prepare_leadfield(cfg);<br><br><br><br><b>Upto this point everything works. My volume conduction model, grads, and grid looks good when verified visually...<br>
<br>I then compute the common filter and apply it to the beamforming of each condition</b><br><br><br>%%%%%%%%%%%%%%%%%%%%% computer common filter%%%%%%%%%%%<br><br>cfg              = [];<br>cfg.method       = 'dics';<br>
cfg.grad              = freqALL_total.grad;<br>cfg.keeptrials        = 'yes';<br>cfg.frequency    = freqALL_total.freq;<br>cfg.grid         = grid;<br>cfg.vol          = vol;<br>cfg.dics.projectnoise = 'yes';<br>
cfg.dics.lambda       = '5%';<br>cfg.dics.keepfilter   = 'yes';<br>cfg.dics.realfilter   = 'yes';<br>cfg.channel         = 'MR'<br>sourceAll = ft_sourceanalysis(cfg, freqALL_total);<br><br>
%%%%%%%%%%%%%%%%%% source for bsl + interest %%%%%%%%%%%%%<br><br>cfg.grid.filter = sourceAll.avg.filter;<br>cfg.grid         = grid;<br>sourcePre_con  = ft_sourceanalysis(cfg, freqPre_total );<br>sourcePost_con = ft_sourceanalysis(cfg, freqPost_total);<br>
<br><br>%%%%%%%%%% Calc difference %%%%%%%%%%%%%%%%%<br><br>sourceDiff = sourcePost_con;<br>sourceDiff.avg.pow = (sourcePost_con.avg.pow - sourcePre_con.avg.pow) ./ sourcePre_con.avg.pow;<br><br><br><br><b>Heres where it falls apart, because I try to source interpolate</b><br>
<br><br>%%%%%%%%%%%%%%%%%%%%% graph time %%%%%%%%%%%%%%%%%%<br><br>% slicemri = ft_volumereslice([], mri);<br>% % mri = ft_volumereslice([],segmentedmri) %%<b> didnt appear to help with the current problem<br></b><br>cfg            = [];<br>
cfg.downsample = 2;<br>cfg.parameter  = 'avg.pow';<br>cfg.coordsys     = 'ctf';<br>cfg.channel         = 'MR'<br>source_diffInt  = ft_sourceinterpolate(cfg, sourceDiff , mri); &&& I also tried segmentedmri, but no difference<br>
<br>It works until it reachs line 237; tmp    = interpmat*tmp; where there is the matrixs are mismatch (interpmat is  a 16777216(256x256x256) x642 matrix, and tmp is a 1 * 642 matrix. From my basic skills I gather that tmp is sourceDiff.avg.pow (the power difference for each leadfield point). interpmat is the interpolation matrix return by<br>
<br>interpmat = interp_ungridded(functional.pos <b>(position of the leadfield locations)</b>, pos (mri voxels), 'projmethod', cfg.interpmethod (<b>nearest</b>), 'sphereradius', cfg.sphereradius) (0.<b>05</b>);<br>
<br>what I get out of this is a 16777216(<b>256x256x256</b> voxels) x642 <b>(leadfield position)</b> matrix<b>. </b>it then undergoes  interpmat(~anatomical.inside(:), :) = 0. My <b>anatomical.inside is all voxels (all of the 256 x 256 x 256 matrix= 1), as a result of the defaults in ft_checkdata</b>.<br>
<br>When I try to find the minimum value in this matrix I get (via min(interpmat) =  All zero sparse: 1-by-642<br><br>I think what is supposed to happen is that the interpmat is a matrix that relates meg to mri space, and as such then mutlipling with a vector that represents the power in meg space, I can see how that would get points of power in mri space. Though this must be wrong since the math is not allowed.... I cannot see where I went off the beaten track. It seems as if other people have not had this problem. <br>
<br>Sorry for the bother,<br><br>Russ Port<br><br>Graduate Student @ Upenn<br><br><br>P.S. thanks to anyone who tries to help in advance...<br><br><br><br><br><br><br><br><u></u><u></u></p></div><p class="MsoNormal"><u></u> <u></u></p>
</div></div></div></div></div><br>_______________________________________________<br>
fieldtrip mailing list<br>
<a href="mailto:fieldtrip@donders.ru.nl">fieldtrip@donders.ru.nl</a><br>
<a href="http://mailman.science.ru.nl/mailman/listinfo/fieldtrip" target="_blank">http://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br></blockquote></div><br>