<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
Hi Duru,
<div class=""><br class="">
</div>
<div class="">
<div>
<blockquote type="cite" class="">
<div class="">
<div dir="ltr" class="">
<div class="">Thank you for your response. It seemed like your suggestion helped, but I thave another potential issue now.</div>
<div class="">The problem is, when I use <i class="">ft_databrowser </i>to visualise the trials after baseline corection loop, I can no longer see the markers, even if I add <i class=""> cfg.plotevents  = 'yes'</i>. I can see that this information exists in
 the data structure, so I'm not sure if this is a problem per se. But the bigger issue is, after running these loops, the data becomes very large (even after being appended), impossible to save, and slows down the rest of my analysis, where regular baseline
 correction doesn't cause this. </div>
</div>
</div>
</blockquote>
<div>
<blockquote type="cite" class="">
<div dir="ltr" class="">
<div class=""> Any ideas where I might be going wrong? I suspect I might have used the wrong kinds of brackets, but the curly brackets as in your suggestion caused an error about cell structures, and when I run it as I wrote, the data structures actually look
 fine.Or it might be the way that I made a loop to append the data, instead of spelling it out for all of the 360 trials.</div>
</div>
</blockquote>
<div class="">
<div dir="ltr" class="">
<div class=""><br class="">
</div>
</div>
</div>
</div>
<div>The data becomes very ‘big’ because you are creating 360 copies of the metadata (which includes the cfg’s of all previous processing steps), AND you are appending the data one trial at a time, which makes this duplication even worse (specifically the duplication
 of the cfgs). </div>
<div>One thing you could do to alleviate this is to save your bl_end_E data structures as a cell-array {}, rather than a struct-array (). Then, you can call ft_appenddata only once with the following syntax: ft_appenddata([], bl_end_E{:}); As a result, you
 will have only 360 copies of the original cfg in the output data structure, rather than 361*180 copies.</div>
<div><br class="">
</div>
<div>The best solution however to me seems to be an extension of the functionality of the baseline correction scheme, where a matricial baselinewindow is supported. I could think of a situation where a check is performed whether size(baselinewindow,1) is equal
 to the number of input trials, and if so, a per trial baselinewindow is applied. if the size is equal to 1, the same baselinewindow will be used for all trials. If the size is something else, an error should be thrown. I would assume that this can be most
 cleanly implemented in the preproc function. We will look forward to a Pull Request on github that impements this!</div>
<div><br class="">
</div>
<br class="">
<blockquote type="cite" class="">
<div class="">
<div dir="ltr" class="">
<div class="">Another somewhat related question, is it possible to have the baseline window outside of the defined trial length? </div>
</div>
</div>
</blockquote>
<div><br class="">
</div>
<div>No. </div>
<div><br class="">
</div>
<div>Best wishes,</div>
<div>Jan-Mathijs</div>
<div><br class="">
</div>
<br class="">
<blockquote type="cite" class="">
<div class="">
<div dir="ltr" class="">
<div class=""><br class="">
</div>
<div class=""> Here is what I did:</div>
<div class=""><br class="">
</div>
<div class=""> for trial_index = 1:360<br class="">
          <br class="">
     cfg                = [];<br class="">
     cfg.demean         = 'yes';<br class="">
     cfg.baselinewindow = [BaselineWindow(trial_index,1) BaselineWindow(trial_index,2)];<br class="">
     cfg.trials         = trial_index;<br class="">
     bl_end_E(trial_index)  = ft_preprocessing(cfg, data_end_E);<br class="">
     <br class="">
 end      <br class="">
 </div>
<div class="">%% This results in the struct:</div>
<div class=""> bl_end_E =   1×360 struct array with 8 fields:<br class="">
    hdr<br class="">
    fsample<br class="">
    trialinfo<br class="">
    sampleinfo<br class="">
    trial<br class="">
    time<br class="">
    label<br class="">
    cfg</div>
<div class=""><br class="">
</div>
<div class="">%% Then I append the data:<br class="">
 data_base_end_E = bl_end_E(1);<br class="">
 <br class="">
 for trial_ind = 2:360<br class="">
          <br class="">
     cfg                 = [];<br class="">
     cfg.keepsampleinfo  = 'yes';<br class="">
     data_base_end_E     = ft_appenddata(cfg,data_base_end_E,bl_end_E(trial_ind));<br class="">
<br class="">
 end<br class="">
 </div>
<div class="">%% This results in losing hdr and fsample fields: data_base_end_E =   struct with fields:<br class="">
<br class="">
         label: {29×1 cell}<br class="">
     trialinfo: [360×4 double]<br class="">
    sampleinfo: [360×2 double]<br class="">
         trial: {1×360 cell}<br class="">
          time: {1×360 cell}<br class="">
           cfg: [1×1 struct]<br class="">
%% So I add them back:</div>
<div class="">  base_end_E.hdr = data_end_E.hdr;<br class="">
  base_end_E.fsample = data_end_E.fsample;<br class="">
<br class="">
</div>
<div class="">    %% Visual data inspection <br class="">
    cfg                   = [];<br class="">
    cfg.viewmode  = 'vertical'; <br class="">
    cfg.continuous = 'no'; <br class="">
    cfg.blocksize   = 1.5;<br class="">
    cfg.channel     = {'all'}; <br class="">
    cfg                   = ft_databrowser(cfg,data_base_end_E);<br class="">
</div>
<div class="">
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">Thanks again for the help!</div>
<div class=""><br class="">
</div>
<div class="">Duru</div>
<div class=""><br class="">
</div>
-- <br class="">
<div dir="ltr" class="m_-3068073089199784581gmail_signature" data-smartmail="gmail_signature">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class=""><i style="font-size:12.8px" class="">Duru G</i><span style="font-family:Calibri,sans-serif;font-size:14.6667px;text-align:justify" class=""><i class="">ü</i></span><i style="font-size:12.8px" class="">n </i><span style="font-family:Calibri,sans-serif;font-size:14.6667px;text-align:justify" class=""><i class="">Ö</i></span><i style="font-size:12.8px" class="">zkan</i>
<div style="font-size:12.8px" class=""><span style="font-size:12.8px" class=""><i class=""><br class="">
</i></span></div>
<div class="">
<div style="font-size:12.8px;color:rgb(136,136,136)" class=""><font size="1" face="trebuchet ms, sans-serif" class=""><b class="">Ph.D. student in Cognitive Social and Affective Neuroscience.<br class="">
</b></font></div>
<div style="font-size:12.8px;color:rgb(136,136,136)" class=""><font size="1" face="trebuchet ms, sans-serif" class=""><b class="">Department of Psychology.<br class="">
University of Rome "La Sapienza".<br class="">
Via dei Marsi 78 - 00185 - Roma.</b></font></div>
<div style="font-size:12.8px;color:rgb(136,136,136)" class=""><font size="1" face="trebuchet ms, sans-serif" class=""><b class=""> </b></font><b style="font-family:"trebuchet ms",sans-serif;font-size:x-small" class="">e-mail: <a href="mailto:vanessa.era@uniroma1.it" style="color:rgb(17,85,204)" target="_blank" class="">durugun.ozkan@uniroma1.it</a></b></div>
<div class=""><font color="#1155cc" size="1" class=""><u class=""><a href="https://agliotilab.org/lab-staff/phd-students/2nd-year#anchor" target="_blank" class="">https://agliotilab.org/lab-staff/phd-students/2nd-year#anchor</a></u></font><br class="">
</div>
</div>
<div class=""><font color="#1155cc" size="1" class=""><br class="">
</font></div>
<div class="">> Hi Duru,<br class="">
<br class="">
>   Use cfg.trials = trial_index<br class="">
>   Put the output in a struct, i.e. bl{trial_index}<br class="">
>   Then combine with ft_append_data([],bl{:});<br class="">
<br class="">
>   Hope this helps,<br class="">
>   Stephen<br class="">
<br class="">
<br class="">
>   On Tue, 17 Sep 2019, 19:30 Duru Gun Ozkan, <<a href="mailto:durugun.ozkan@uniroma1.it" target="_blank" class="">durugun.ozkan@uniroma1.it</a>><br class="">
>   wrote:<br class="">
<br class="">
> Hi everyone,<br class="">
><br class="">
> I have a question regarding specifying a different baseline correction<br class="">
> time for each trial in ft_preprocessing.<br class="">
> I had 360 audio stimuli all of which had different lengths. My trigger is<br class="">
> located at the end of each stimuli, and I would like to place the baseline<br class="">
> correction between 200 ms before stimulus start and stimulus start.<br class="">
> I have a matrix for cfg.baselinewindow called BaselineWindow such as this:<br class="">
> -1.83018 -1.630182<br class="">
> -1.69807 -1.498071<br class="">
> -0.58653 -0.38653<br class="">
> -1.07604 -0.876039<br class="">
> -2.2608 -2.060803<br class="">
> -0.80863 -0.608632<br class="">
> -1.55663 -1.356629<br class="">
> -0.94261 -0.742605<br class="">
> -1.20845 -1.008448 ...<br class="">
> I tried to create a loop:<br class="">
><br class="">
> for trial_index = 1:360<br class="">
><br class="">
>      cfg = [];<br class="">
>      cfg.demean        = 'yes';<br class="">
>      cfg.baselinewindow = [BaselineWindow(trial_index,1)<br class="">
> BaselineWindow(trial_index,2)];<br class="">
><br class="">
>      data_baselined_end_E = ft_preprocessing(cfg, data_end_E);<br class="">
><br class="">
>  end<br class="">
><br class="">
> This didn't work because it kept running the preprocessing with all the<br class="">
> baselines with all trials, instead of keeping to its specific trial.<br class="">
><br class="">
> My question is, is there another way to specify individual baselines for<br class="">
> individual trials? Or can anyone suggest to improve this loop to have the<br class="">
> data preprocessed with its specific baseline windows?<br class="">
><br class="">
> Thank you in advance.<br class="">
><br class="">
> Best,<br class="">
><br class="">
>  <br class="">
<font color="#1155cc" size="1" class=""><br class="">
</font></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
_______________________________________________<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="">
</div>
</body>
</html>