<div dir="ltr"><div class="gmail_default" style="color:rgb(51,51,153)">Hi Antonio, yes, here's a solution below, plz give it a try and let me know. It will be nice if you can include your working updated code so other eeglabers can easily learn from your experience. Cheers.</div><div class="gmail_default" style="color:rgb(51,51,153)"><br></div><div class="gmail_default" style="color:rgb(51,51,153)"><br></div><div class="gmail_default" style="color:rgb(51,51,153)">*******BEGIN</div><div class="gmail_default" style="color:rgb(51,51,153)"><br></div><div class="gmail_default" style="color:rgb(51,51,153)">The code line example below should throw up the same window that gets thrown up when going from the GUI (Tools>Reject Data Epochs and clicking/using the Find Abnormal Trends), which, upon running from the gui, displays a plot of the epochs, including previously marked epochs. After getting the correct plot window which showed epochs and showed pre-selected epochs and allowed me to change which epochs were selected, I then typed eegh to get the function and settings that were run to throw up the proper window. I then modified the pop_rejtrend settings so that no epochs are selected by the function (setting a high threshold and low R), and so that it shows a plot of previously marked epochs, and allows updating of the epochs by changing/adding/removing marks on epochs. You may need to modify settings slightly. There are otherways to get the data and previously selected epochs plotted, but this should work for you for now until you become an expert! Code lines below, and extra notes further below.</div><div class="gmail_default" style="color:rgb(51,51,153)">







<p class="gmail-p1"><br></p><p class="gmail-p1">*************run these three llines instead of the 2 old eegplot lines in Step 2 that I previously emailed you.</p><p class="gmail-p1">numberofsamples=EEG.srate * EEG.xmax; thecurrentchannels = 1:(EEG.nbchan); % gets samples per epoch and channel numbers</p><p class="gmail-p1">








</p><p class="gmail-p1">EEG = pop_rejtrend(EEG,1,thecurrentchannels ,numberofsamples,1000000,0,2,0); %opens epoch window with marks, R set to 0)</p><p class="gmail-p1"><span style="font-size:12.8px">  [ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET); %updates eeglab </span><br></p><p class="gmail-p1">*************</p><p class="gmail-p1"><br></p><p class="gmail-p1">Additional notes for Antonio:</p><p class="gmail-p1">Note that you'll have two buttons to press after making your changes. The Update Marks button, and the ok button in the reminder window that pops up after. </p><p class="gmail-p1">Review closely the pop_rejtrend documentation for more info. Also checkout the eegplot documentation for other ways to show similar information.</p><p class="gmail-p1">Whenever possible, remember to test via the gui steps and eegh, and one can usually find a solution and the correct function/settings. If you can do it in the gui, you can do it via code, usually :) In other words, if you can do it via the gui, you're a few steps away from doing it via code (but not vice versa!). In particular, beginners doing eeglab coding are best off mimicking eegh output closely</p><p class="gmail-p1">Also, for any functions you might want to use (and the ones used most by eeglab), take time to review the documentation (help nameOfFunction, or doc nameOfFunction). </p><p class="gmail-p1">*remember to adequately update/save your marked epochs (and eeglab structure) before showing/viewing existing selection. For example, after each step of artifactual epoch detection.</p><p class="gmail-p1">*I think I have the R setting correct in the code line, at 0,  but you may need to reverse it to 1.</p><p class="gmail-p1">The "update marks" button can be changed to Reject if one modifies the pop_rejtrend settings. This would reject from gui rather than in code as in example in previous email<br></p><p class="gmail-p1"><br></p><p class="gmail-p1">*************END<br></p><p class="gmail-p1"><br></p><p class="gmail-p1"><br></p><p class="gmail-p1"><br></p><p class="gmail-p1"><br></p><p class="gmail-p1"><br></p><p class="gmail-p1"><br></p><p class="gmail-p1"><br></p><p class="gmail-p1"><br></p></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 19, 2017 at 6:43 AM, Antonio Maffei <span dir="ltr"><<a href="mailto:antonio.maffei@phd.unipd.it" target="_blank">antonio.maffei@phd.unipd.it</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div style="font-family:arial,helvetica,sans-serif">Hello Tarik,</div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">thank you for the reply. </div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">I tried your code but the problem remains since, when the data are plotted, the epochs marked for rejection are not highlighted in the plot, so it is not possible to visually confirm the goodness of the rejection procedure.</div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">Do you have any further suggestion to solve this issue?</div><span class="gmail-"><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">Antonio</div><div class="gmail_extra"><br clear="all"><div><div class="gmail-m_8844248592987497619m_8123447932483736910gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><span style="font-family:arial,helvetica,sans-serif">Antonio Maffei, Ph.D. Student<br></span></div><div dir="ltr"><span style="font-family:arial,helvetica,sans-serif"><br>Department of General Psychology (DPG)<br>University of Padova<br>Via Venezia 8 - 35131  <br>Padova, Italy<br><br>email: <a href="mailto:antonio.maffei@phd.unipd.it" target="_blank">antonio.maffei@phd.unipd.it</a><br></span></div><div><span style="font-family:arial,helvetica,sans-serif">office: 049 8277424</span></div></div></div></div></div></div></div></div></div></div><br></div></span></div></blockquote><div><br></div><div><br></div><div><br></div><div class="gmail_default" style="font-size:12.8px;color:rgb(51,51,153)">Hello Antonio,<br><br></div><div class="gmail_default" style="font-size:12.8px;color:rgb(51,51,153)">Try something like the below within your script loop, which throws up a gui, and then computes epochs-to-remove and then removes them. <br></div><div class="gmail_default" style="font-size:12.8px;color:rgb(51,51,153)">The following might also be helpful: Reviewing the eeglab scripting online tutorials, and the eeg.reject structure in your eeglab files. The documentation within functions is also useful.</div><div class="gmail_default" style="font-size:12.8px;color:rgb(51,51,153)"><br></div><div class="gmail_default" style="font-size:12.8px;color:rgb(51,51,153)">Does the below work for you?<br></div><div class="gmail_default" style="font-size:12.8px;color:rgb(51,51,153)"><br></div><div class="gmail_default" style="font-size:12.8px;color:rgb(51,51,153)">.......<br>1.Run various artifact-epoch detection methods<br></div><div class="gmail_default" style="font-size:12.8px;color:rgb(51,51,153)">then<br><span class="gmail-m_1460326573802964701gmail-m_-7166579895331954064gmail-m_7350188131009688029gmail-Apple-converted-space">      [ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET);</span><br></div><div class="gmail_default" style="font-size:12.8px;color:rgb(51,51,153)"><br></div><div class="gmail_default" style="font-size:12.8px;color:rgb(51,51,153)">2. Then, within code, run the function command for showing eegplot of the epochs.<br><br>pop_eegplot( EEG, 1, 1, 1);<br><br></div><div class="gmail_default" style="font-size:12.8px;color:rgb(51,51,153)">3. The user should then be able to walk through the epochs, see the ones that have been selected and those that have not been, make changes if necessary, and then should close the gui, and then the code should keep running the following:<br><br><span class="gmail-m_1460326573802964701gmail-m_-7166579895331954064gmail-m_7350188131009688029gmail-Apple-converted-space">      [ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET);</span><br><br>EEG = eeg_rejsuperpose( EEG, 1, 1, 1, 1, 1, 1, 1, 1);  %gives a variable named as follows with all epochs to reject: EEG.reject.rejglobal<br><br><span class="gmail-m_1460326573802964701gmail-m_-7166579895331954064gmail-m_7350188131009688029gmail-Apple-converted-space">      [ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET);</span><br></div><div class="gmail_default" style="font-size:12.8px;color:rgb(51,51,153)"><br></div><div class="gmail_default" style="font-size:12.8px;color:rgb(51,51,153)">5. run epoch rejection using that list of epochs <br></div><div class="gmail_default" style="font-size:12.8px;color:rgb(51,51,153)">for example, as follows<br><br>     EEG = pop_rejepoch( EEG, EEG.reject.rejglobal ,0);  <br><span class="gmail-m_1460326573802964701gmail-m_-7166579895331954064gmail-m_7350188131009688029gmail-Apple-converted-space">      [ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET);</span><br></div><div><span style="color:rgb(51,51,153);font-size:12.8px">........</span> </div></div><br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_default" style="font-size:12.8px;font-family:arial,helvetica,sans-serif">Dear EEGLab users,</div><div class="gmail_default" style="font-size:12.8px;font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-size:12.8px;font-family:arial,helvetica,sans-serif">I have a problem in the scripting of a pipeline for semi-automated epoch rejection.</div><div class="gmail_default" style="font-size:12.8px;font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-size:12.8px;font-family:arial,helvetica,sans-serif">The step I would like to accomplish are:</div><div class="gmail_default" style="font-size:12.8px;font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-size:12.8px;font-family:arial,helvetica,sans-serif">1) Importing the dataset</div><div class="gmail_default" style="font-size:12.8px;font-family:arial,helvetica,sans-serif">2) Performing epoch rejection based on amplitude</div><div class="gmail_default" style="font-size:12.8px;font-family:arial,helvetica,sans-serif">3) Performing epoch rejection based on linear trends</div><div class="gmail_default" style="font-size:12.8px;font-family:arial,helvetica,sans-serif">4) Review the epochs visually</div><div class="gmail_default" style="font-size:12.8px;font-family:arial,helvetica,sans-serif">5) Confirm rejection</div><div class="gmail_default" style="font-size:12.8px;font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-size:12.8px;font-family:arial,helvetica,sans-serif">My attempt is the following:</div><div class="gmail_default" style="font-size:12.8px;font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-size:12.8px;font-family:arial,helvetica,sans-serif"><p class="gmail-m_6480914606465244328gmail-p1"><span class="gmail-m_6480914606465244328gmail-s1">for</span> i = 1:length(filenames)</p><p class="gmail-m_6480914606465244328gmail-p3"><span class="gmail-m_6480914606465244328gmail-s2">    </span>% Import EEG data</p><p class="gmail-m_6480914606465244328gmail-p1"><span class="gmail-m_6480914606465244328gmail-Apple-converted-space">    </span>dataset_name = filenames_epochs{i};</p><p class="gmail-m_6480914606465244328gmail-p1"><span class="gmail-m_6480914606465244328gmail-Apple-converted-space">    </span>EEG = pop_loadset(<span class="gmail-m_6480914606465244328gmail-s3">'filename'</span>, dataset_name, <span class="gmail-m_6480914606465244328gmail-s3">'filepath'</span>, dirpath);</p><p class="gmail-m_6480914606465244328gmail-p3"><span class="gmail-m_6480914606465244328gmail-s2">    </span>% Reject on amplitude threshold</p><p class="gmail-m_6480914606465244328gmail-p1"><span class="gmail-m_6480914606465244328gmail-Apple-converted-space">    </span>EEG = pop_eegthresh(EEG, 1, [<span class="gmail-aBn" tabindex="0"><span class="gmail-aQJ">1:32</span></span>], -100, 100, 0, 2.0391, 1, 0);</p><p class="gmail-m_6480914606465244328gmail-p1">    % Reject trends</p><p class="gmail-m_6480914606465244328gmail-p1"><span class="gmail-m_6480914606465244328gmail-Apple-converted-space">    </span>EEG = pop_rejtrend(EEG, 1, [<span class="gmail-aBn" tabindex="0"><span class="gmail-aQJ">1:32</span></span>], 262, 0.5, 0.3, 1, 0, 0);</p><p class="gmail-m_6480914606465244328gmail-p1">    % Review visually the marked epochs and confirm rejection</p><p class="gmail-m_6480914606465244328gmail-p1">    ??????????????????????????????<wbr>?????</p><p class="gmail-m_6480914606465244328gmail-p2"><span class="gmail-m_6480914606465244328gmail-s2">    </span>% Store the dataset</p><p class="gmail-m_6480914606465244328gmail-p1"><span class="gmail-m_6480914606465244328gmail-Apple-converted-space">    </span>[ALLEEG, EEG, CURRENTSET] = eeg_store(ALLEEG, EEG);</p><p class="gmail-m_6480914606465244328gmail-p1">end</p><p class="gmail-m_6480914606465244328gmail-p1">I know how to achieve this by GUI but, as you can see, I fail to understand how to review the marked epochs visually within the script.</p><p class="gmail-m_6480914606465244328gmail-p1">Thank you for the help,</p><p class="gmail-m_6480914606465244328gmail-p1">Antonio</p></div><div class="gmail_default" style="font-size:12.8px;font-family:arial,helvetica,sans-serif"><br></div><div style="font-size:12.8px"><div class="gmail-m_6480914606465244328gmail_signature"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><span style="font-family:arial,helvetica,sans-serif">Antonio Maffei, Ph.D. Student<br></span></div><div dir="ltr"><span style="font-family:arial,helvetica,sans-serif"><br>Department of General Psychology (DPG)<br>University of Padova<br>Via Venezia 8 - 35131  <br>Padova, Italy<br><br>email: <a href="mailto:antonio.maffei@phd.unipd.it" target="_blank">antonio.maffei@phd.unipd.it</a><br></span></div><div><span style="font-family:arial,helvetica,sans-serif">office: 049 8277424</span></div></div></div></div></div></div></div></div></div>