<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
Hi Christian,
<div class=""><br class="">
</div>
<div class="">The code ‘an sich’ looks OK’ish, although I don’t know your motivation for doing:</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
   [SourceData] = ft_sourcedescriptives([], SourceData);</div>
<br class="Apple-interchange-newline">
</div>
<div class="">Also, it is still not clear why the coherence matrix is larger than the number of dipoles in the source model.</div>
<div class="">You may want to check the output SourceData after ft_sourceanalysis, and compare it with the output of ft_sourcedescriptives.</div>
<div class="">Also, you may want to go through ft_connectivityanalysis step-by-step, using the debugging features in matlab (set a breakpoint at the beginning of the function, which allows you to step through and inspect the result of the execution of each
 line of code in the function). </div>
<div class=""><br class="">
</div>
<div class="">Things to look at with priority are the presence of a SourceData.avg.mom field, and the dimension of each of the elements (after ft_sourceanalysis, and after ft_sourcedescriptives), and the input/output to the call to univariate2bivariate (which
 is called from ft_connectivityanalysis).</div>
<div class=""><br class="">
</div>
<div class="">Best wishes,</div>
<div class="">Jan-Mathijs</div>
<div class=""><br class="">
</div>
<div>
<blockquote type="cite" class="">
<div class="">On 22 May 2019, at 16:34, Christian Mista <<a href="mailto:cmista@ingenieria.uner.edu.ar" class="">cmista@ingenieria.uner.edu.ar</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
Hi <span class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
</span>Jan-Mathijs,</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<br class="">
</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
Thank you for your replay. I tried to describe the problem as clear as possible, but it seems I ended omitting information in the process. Here is all my code so far. I still can't find what i'm doing wrong.</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<br class="">
</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
My data is a preprocessed continuous eeg recording.    <br class="">
</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<br class="">
</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<span style="color:rgb(106,168,79)" class="">% prepare layout</span><br class="">
    cfg = [];<br class="">
<span style="color:rgb(106,168,79)" class="">%I have to rotate the axis layout </span>
<br class="">
    aux_elec         = chanloc.elec;<br class="">
    aux_elec.pnt(:,1) = -chanloc.elec.pnt(:,2);<br class="">
    aux_elec.pnt(:,2) = chanloc.elec.pnt(:,1);<br class="">
<span style="color:rgb(106,168,79)" class="">%update direction</span><br class="">
    chanloc.elec.pnt = aux_elec.pnt;<br class="">
<span style="color:rgb(106,168,79)" class="">%layout for plotting</span><br class="">
    cfg.elec          = chanloc.elec;<br class="">
    layout            = ft_prepare_layout(cfg);</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<br class="">
</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<span style="color:rgb(106,168,79)" class="">% subdivide into trials of 1 seconds 10% overlap</span><br class="">
     cfg              = [];<br class="">
<span style="color:rgb(106,168,79)" class="">% single number (in unit of time, typically seconds) of the required snippets</span><br class="">
     cfg.length      = 1;<br class="">
<span style="color:rgb(106,168,79)" class="">% single number (between 0 and 1 (exclusive)) specifying the fraction of overlap between snippets (0 = no overlap)</span><br class="">
     cfg.overlap     = 0.1;<br class="">
<span style="color:rgb(106,168,79)" class="">%cut</span><br class="">
     data            = ft_redefinetrial(cfg, data); </div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<br class="">
</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<span style="color:rgb(106,168,79)" class="">%%  calculate cross-spectrum</span><br class="">
    cfg               = [];<br class="">
    cfg.method      = 'mtmfft';<br class="">
    cfg.taper         = 'hanning';</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<span style="color:rgb(106,168,79)" class="">%For connectivity analysis we need power and phase -> 'fourier'</span><br class="">
    cfg.output        = 'fourier';<br class="">
    cfg.keeptrials    = 'yes';<br class="">
<span style="color:rgb(106,168,79)" class="">%frequency of interest foilim at 10 Hz +/- 1 Hz</span><br class="">
    cfg.foi            = 10;<br class="">
    cfg.tapsmofrq    = 1;<br class="">
<span style="color:rgb(147,196,125)" class="">%frequency analysis</span><br class="">
    freq1             = ft_freqanalysis(cfg, data);</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<span style="color:rgb(56,118,29)" class=""><br class="">
</span></div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<span style="color:rgb(56,118,29)" class="">%% Calculate source model<br class="">
</span></div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
    [headmodel sourcemodel] = read_custom_head_source_model(freq1);  <span style="color:rgb(106,168,79)" class="">
<span style="color:rgb(56,118,29)" class=""><b class="">%function at the end of the email</b></span><br class="">
</span></div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<br class="">
</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<span style="color:rgb(56,118,29)" class="">%% do the source reconstruction</span><br class="">
    cfg                    = [];<br class="">
    cfg.frequency         = freq1.freq;<br class="">
    cfg.method            = 'pcc';                   % Dynamic Imaging of Coherent Sources   
<br class="">
    cfg.headmodel        = headmodel;<br class="">
    cfg.grid                = sourcemodel;          % Our grid and the leadfield<br class="">
    cfg.pcc.projectnoise   = 'yes';                   % estimate noise<br class="">
    cfg.pcc.lambda        = '10%';                  % how to regularise<br class="">
    cfg.pcc.keepfilter      = 'yes';                  % keep the spatial filter in the output<br class="">
    cfg.pcc.realfilter       = 'yes';                  % retain the real values<br class="">
    cfg.keeptrials          = 'yes';<br class="">
    cfg.senstype           = 'eeg';<br class="">
<br class="">
    SourceData = ft_sourceanalysis(cfg, freq1);<br class="">
   [SourceData] = ft_sourcedescriptives([], SourceData);</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<br class="">
</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<span style="color:rgb(56,118,29)" class=""><b class="">   %% connectivity (this is the code I posted before)</b></span><br class="">
    cfg         = [];<br class="">
    cfg.method  = 'coh';<br class="">
    cfg.complex = 'absimag';<br class="">
    source_conn = ft_connectivityanalysis(cfg, SourceData);<br class="">
    <br class="">
<span style="color:rgb(106,168,79)" class="">    %The conectome</span><br class="">
    figure;imagesc(source_conn.cohspctrm);<br class="">
    <br class="">
    <span style="color:rgb(106,168,79)" class="">%Parcellation</span><br class="">
    atlas = ft_read_atlas('/fieldtrip-master/template/atlas/aal/ROI_MNI_V4.nii');<br class="">
    <br class="">
    cfg = [];<br class="">
    cfg.interpmethod='nearest';<br class="">
    cfg.parameter='tissue';<br class="">
    [int_atlas] = ft_sourceinterpolate(cfg, atlas, source_conn);<br class="">
    int_atlas.pos = source_conn.pos; % otherwise the parcellation won't work<br class="">
    <br class="">
    % and call ft_sourceparcellate:<br class="">
    cfg = [];<br class="">
    cfg.parcellation = 'tissue';<br class="">
    cfg.parameter    = 'cohspctrm';<br class="">
    parc_conn = ft_sourceparcellate(cfg, source_conn, int_atlas);<br class="">
<br class="">
    figure;imagesc(parc_conn.cohspctrm);</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<br class="">
</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
+++ continue code<br class="">
</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<br class="">
</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<br class="">
</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<span style="color:rgb(11,83,148)" class="">function</span> [hdm lf] = read_custom_head_source_model(data)</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<span style="color:rgb(147,196,125)" class="">%% read labels and search positions in template</span><br class="">
    elec = ft_read_sens('standard_1020.elc');<br class="">
<span style="color:rgb(106,168,79)" class="">    % Change unit for visivility</span><br class="">
    data.elec.unit = 'mm';<br class="">
</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<br class="">
</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
    for labelindex = 1:length(data.label)<br class="">
<span style="color:rgb(106,168,79)" class="">       %position of my electrodes in the template standard_1020</span><br class="">
       Index = find(strcmpi(elec.label, data.label{labelindex}));<br class="">
       <br class="">
<span style="color:rgb(106,168,79)" class="">       %writing the real position of the electrodes in my data</span><br class="">
       data.elec.chanpos(labelindex,:) = elec.chanpos(Index,:);<br class="">
       data.elec.elecpos(labelindex,:) = elec.elecpos(Index,:); <br class="">
    end<br class="">
    <br class="">
<span style="color:rgb(106,168,79)" class="">% Load template head model</span><br class="">
    load('/fieldtrip-master/template/headmodel/symetric_headmodel.mat')<br class="">
    headmodel = ft_convert_units(headmodel, data.elec.unit);<br class="">
 </div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<span style="color:rgb(106,168,79)" class="">%% compute the leadfield</span><br class="">
    cfg                = [];<br class="">
    cfg.elec           = data.elec;<br class="">
    cfg.elec.unit     = 'mm';                   <br class="">
    cfg.headmodel    = headmodel;<br class="">
    cfg.grid.resolution = 20;           % use a 3-D grid with a 20 mm resolution<br class="">
    [lf] = ft_prepare_leadfield(cfg);<br class="">
<span style="color:rgb(11,83,148)" class="">end</span></div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<br class="">
</div>
<div class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;">
<div class="">I attached a figure how the source nai index looks in a sourceplot. Thanks for your help.</div>
<div class=""><br class="">
</div>
<div class="">All the best,</div>
<div class="">Christian<br class="">
</div>
</div>
</div>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr"><br class="">
</div>
<div dir="ltr" class="gmail_attr"></div>
<div dir="ltr" class="gmail_attr">El mar., 21 may. 2019 a las 15:44, Schoffelen, J.M. (Jan Mathijs) (<<a href="mailto:jan.schoffelen@donders.ru.nl" target="_blank" class="">jan.schoffelen@donders.ru.nl</a>>) escribió:<br class="">
</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="">Hi Christian,
<div class=""><br class="">
<div class="">I guess you need to figure out why the dimension of the coherence matrix does not match the expectations.</div>
<div class="">Based on the information you provide (i.e. the lack thereof: it’s not clear how you compute SourceData, and how you spectrally transformed your sensor data that goes into the source reconstruction step) there is lottle to go on.</div>
<div class=""><br class="">
</div>
<div class="">Best wishes,</div>
<div class=""><span class="gmail_default" style="font-family: tahoma, sans-serif; font-size: small;"></span>Jan-Mathijs</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""> <br class="">
<div class="">
<blockquote type="cite" class="">
<div class="">On 21 May 2019, at 19:27, Christian Mista <<a href="mailto:cmista@ingenieria.uner.edu.ar" target="_blank" class="">cmista@ingenieria.uner.edu.ar</a>> wrote:</div>
<br class="m_3586701746260788978gmail-m_53341994689760994Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">
<div style="font-family:tahoma,sans-serif;font-size:small" class="">
<div style="font-family:tahoma,sans-serif;font-size:small" class="">Hi FieldTrip community,</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class=""><br class="">
</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class="">I've been trying to perform a connectivity analysis using a 66 eeg recording database. So far, I've being able to solve the sourceanalysis (following the tutorial
<a href="http://www.fieldtriptoolbox.org/tutorial/networkanalysis/" target="_blank" class="">
http://www.fieldtriptoolbox.org/tutorial/networkanalysis/</a>) and plot the source activity. However, the problem starts when I'm trying the connectivity analysis. Any grid dimension lower than 20 mm in the sourcemodel calculation results in a matlab error
 (Out of memory) in the connectivity analysis. I guess that a grid dimension lower than 20 mm conveys to huge matrix sizes, not manageable by my OS (linux + Matlab).
<br class="">
</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class=""><br class="">
</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class="">%% This is how I compute the sourcemodel (run ok)<br class="">
    cfg                 = [];<br class="">
    cfg.elec            = data.elec;<br class="">
    cfg.elec.unit = 'mm';                   % unit in cm<br class="">
    cfg.headmodel       = headmodel;<br class="">
    cfg.grid.resolution = 20;     % use a 3-D grid with a 20 mm resolution<br class="">
    [lf] = ft_prepare_leadfield(cfg);</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class=""><br class="">
</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class=""><br class="">
</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class="">After computing the sourcemodel using the 20 mm grid, I have issues to parcellate my data. My main concern is about the mismatch size between the connectivity matrix and the atlas.
<br class="">
</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class=""><br class="">
</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class="">source_conn =<br class="">
          dim: [7 9 8]<br class="">
       inside: [504×1 logical]<br class="">
          pos: [504×3 double]<br class="">
    cohspctrm: [5544×5544 double]<br class="">
       dimord: 'pos_pos_freq'<br class="">
         freq: 10<br class="">
          cfg: [1×1 struct]</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class=""><br class="">
</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class=""><br class="">
atlas = <br class="">
</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class="">            dim: [91 109 91]<br class="">
            hdr: [1×1 struct]<br class="">
      transform: [4×4 double]<br class="">
           unit: 'mm'<br class="">
         tissue: [91×109×91 double]<br class="">
    tissuelabel: {1×116 cell}<br class="">
       coordsys: 'mni'</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class=""><br class="">
</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class="">I'd tried to interpolate and parcellate the matrix, but I must be missing or confusing something... Below is the code to calculate the connectivity and the parcellation.
</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class=""><br class="">
</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class="">%% connectivity<br class="">
    cfg         = [];<br class="">
    cfg.method  = 'coh';<br class="">
    cfg.complex = 'absimag';<br class="">
    source_conn = ft_connectivityanalysis(cfg, SourceData);<br class="">
    <br class="">
    %The conectome<br class="">
    figure;imagesc(source_conn.cohspctrm); %5544x5544 double<br class="">
    <br class="">
    %Parcellation<br class="">
    atlas = ft_read_atlas('/fieldtrip-master/template/atlas/aal/ROI_MNI_V4.nii');<br class="">
    <br class="">
    cfg = [];<br class="">
    cfg.interpmethod='nearest';<br class="">
    cfg.parameter='tissue';<br class="">
    [int_atlas] = ft_sourceinterpolate(cfg, atlas, source_conn);<br class="">
    int_atlas.pos = source_conn.pos; % otherwise the parcellation won't work<br class="">
    <br class="">
    % and call ft_sourceparcellate:<br class="">
    cfg = [];<br class="">
    cfg.parcellation = 'tissue';<br class="">
    cfg.parameter    = 'cohspctrm';<br class="">
    parc_conn = ft_sourceparcellate(cfg, source_conn, int_atlas);<br class="">
<br class="">
    figure;imagesc(parc_conn.cohspctrm);<br class="">
</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class=""><br class="">
</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class="">++Error in command windows matlab
<br class="">
</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class=""><br class="">
</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class="">there are in total 504 positions, 230 positions are inside the brain, 181 positions have a label<br class="">
168 of the positions inside the brain have a label<br class="">
168 of the labeled positions are inside the brain<br class="">
62 of the positions inside the brain do not have a label<span style="color:rgb(255,0,0)" class=""><span style="background-color:rgb(255,0,0)" class=""><br class="">
<span style="background-color:rgb(255,255,255)" class="">Error using ft_notification (line 340)<br class="">
unsupported dimord unknown_unknown_freq<br class="">
<br class="">
Error in ft_error (line 39)<br class="">
  ft_notification(varargin{:});<br class="">
<br class="">
Error in ft_sourceparcellate (line 309)<br class="">
    ft_error('unsupported dimord %s', dimord{i})</span></span></span></div>
<div style="font-family:tahoma,sans-serif;font-size:small" class=""><br class="">
</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class="">Two questions
<br class="">
</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class="">-Is 20 mm the min grid size to calculate connectivity?</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class="">-What I'm missing in the parcellation process?</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class=""><br class="">
</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class="">I would really appreciate any advice, I've been scratching my head for a while on this one.</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class=""><br class="">
</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class="">Best,</div>
<div style="font-family:tahoma,sans-serif;font-size:small" class="">Christian  </div>
</div>
</div>
_______________________________________________<br class="">
fieldtrip mailing list<br class="">
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" target="_blank" class="">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br class="">
<a href="https://doi.org/10.1371/journal.pcbi.1002202" target="_blank" class="">https://doi.org/10.1371/journal.pcbi.1002202</a><br class="">
</div>
</blockquote>
</div>
<br class="">
</div>
</div>
</div>
_______________________________________________<br class="">
fieldtrip mailing list<br class="">
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" rel="noreferrer" target="_blank" class="">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br class="">
<a href="https://doi.org/10.1371/journal.pcbi.1002202" rel="noreferrer" target="_blank" class="">https://doi.org/10.1371/journal.pcbi.1002202</a><br class="">
</blockquote>
</div>
</div>
<span id="cid:f_jvzbiuep1"><sourceNAI.jpg></span>_______________________________________________<br class="">
fieldtrip mailing list<br class="">
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" class="">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br class="">
https://doi.org/10.1371/journal.pcbi.1002202<br class="">
</div>
</blockquote>
</div>
<br class="">
</body>
</html>