<div dir="ltr"><br><div class="gmail_extra">Here is some code I have used to trim data away from datasets that are substantially longer than the actual periods of interest. The code basically looks for inter-trial intervals longer than a few seconds (you can adjust that of course), and then takes those time points at either end of a long "event-less" spell as the time-points to feed into pop_select for eliminating.<br>
<br>%%% Here we will identify all the segments of the recording<br>%%% that are in between event blocks, and we'll delete those segments from the<br>%%% continuous dataset.<br>            indices_in_datapoints_to_delete = [];<br>
            time_thresh_between_events_in_sec = 5;<br>            time_thresh_between_events_in_pts = time_thresh_between_events_in_sec * EEG.srate;<br>            <br>            for event_index =  1:length(EEG.event)<br>
                <br>                prev_event_latency_in_pts = [];<br>                this_event_latency_in_pts = [];<br>                next_event_latency_in_pts = [];<br>                <br>                if event_index == 1<br>
                    <br>                    prev_event_latency_in_pts = EEG.event(event_index).latency;<br>                    this_event_latency_in_pts = EEG.event(event_index).latency;<br>                    next_event_latency_in_pts = EEG.event(event_index+1).latency;<br>
                    <br>                    indices_in_datapoints_to_delete =     <br>                                      [indices_in_datapoints_to_delete;   1  <br>                                      ((EEG.event(event_index).latency)-(2*EEG.srate))];<br>
                    <br>                elseif event_index == length(EEG.event)<br>                    <br>                    <br>                    this_event_latency_in_pts = EEG.event(event_index).latency;<br>                    <br>
                    indices_in_datapoints_to_delete = <br>                         [indices_in_datapoints_to_delete; this_event_latency_in_pts <br>                         (EEG.xmax*EEG.srate)];<br>                    <br>
                else<br>                    <br>                    prev_event_latency_in_pts = EEG.event(event_index - 1).latency;<br>                    this_event_latency_in_pts = EEG.event(event_index).latency;<br>                    next_event_latency_in_pts = EEG.event(event_index+1).latency;<br>
                    <br>                end<br>                <br>                prev_inter_trial_latency = this_event_latency_in_pts - <br>                                         prev_event_latency_in_pts;<br>                <br>
                next_inter_trial_latency = next_event_latency_in_pts - <br>                                          this_event_latency_in_pts;<br>                <br>                if next_inter_trial_latency > time_thresh_between_events_in_pts<br>
                    <br>                    indices_in_datapoints_to_delete = <br>                             [indices_in_datapoints_to_delete;  (this_event_latency_in_pts <br>                          + (2*EEG.srate)) (next_event_latency_in_pts - (2*EEG.srate))];<br>
                    <br>                    <br>                elseif  prev_inter_trial_latency > time_thresh_between_events_in_pts<br>                    <br>                    indices_in_datapoints_to_delete = <br>
                          [indices_in_datapoints_to_delete;  (prev_event_latency_in_pts <br>                          + (2*EEG.srate)) (this_event_latency_in_pts - 2*EEG.srate)];<br>                    <br>                end<br>
                <br>            end %%% END for event_index loop<br>            <br>            EEG = pop_select(EEG, 'nopoint', indices_in_datapoints_to_delete);<br>            <br>            EEG.comments = pop_comments(EEG.comments, '', 'Identified the periods of time in between runs (i.e. blocks of trials) and deleted those.', 1);<br>
<br></div><div class="gmail_extra">Hope that helps. Also "Out of Memory" errors can sometimes be solved by increasing your MATLAB Java Heap Memory in the MATLAB > Preferences > General section.<br><br></div>
<div class="gmail_extra">Good luck,<br><br>James<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 13, 2014 at 12:25 PM,  <span dir="ltr"><<a href="mailto:eeglablist-request@sccn.ucsd.edu" target="_blank">eeglablist-request@sccn.ucsd.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Send eeglablist mailing list submissions to<br>
        <a href="mailto:eeglablist@sccn.ucsd.edu">eeglablist@sccn.ucsd.edu</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="http://sccn.ucsd.edu/mailman/listinfo/eeglablist" target="_blank">http://sccn.ucsd.edu/mailman/listinfo/eeglablist</a><br>
or, via email, send a message with subject or body 'help' to<br>
        <a href="mailto:eeglablist-request@sccn.ucsd.edu">eeglablist-request@sccn.ucsd.edu</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:eeglablist-owner@sccn.ucsd.edu">eeglablist-owner@sccn.ucsd.edu</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of eeglablist digest..."<br>
<br>Today's Topics:<br>
<br>
   1. EEGlab function to trim datasets (Brent A. Field)<br>
   2. UK EEGLAB workshop September 2015 (Elizabeth Milne)<br>
   3. Re: EEGlab function to trim datasets (Tarik S Bel-Bahar)<br>
   4. Why does GUI not update the "filename" field after I      save a<br>
      new dataset? (James Jones-Rounds)<br>
   5. Re: How to "difference plot" of coherences from two different<br>
      datasets or conditions in SIFT and/or EEGLAB (James Jones-Rounds)<br>
<br><br>---------- Forwarded message ----------<br>From: "Brent A. Field" <<a href="mailto:bfield@princeton.edu">bfield@princeton.edu</a>><br>To: "<a href="mailto:eeglablist@sccn.ucsd.edu">eeglablist@sccn.ucsd.edu</a>" <<a href="mailto:eeglablist@sccn.ucsd.edu">eeglablist@sccn.ucsd.edu</a>><br>
Cc: <br>Date: Wed, 12 Feb 2014 22:26:10 +0000<br>Subject: [Eeglablist] EEGlab function to trim datasets<br>





<div link="blue" vlink="purple" lang="EN-US">
<div>
<p class="MsoNormal">I running a computationally intensive analysis on a high-end cluster, but have been confounded because I periodically hit a Matlab Out of Memory error. The input data has a high sampling rate, has a lot of channels, and is collected over
 a long period. These can be simplified at later stages, but the first step requires inputting roughly a 4 GB continuous data file, with memory requirement far beyond that to actually run the analysis. I won’t go into it, but there is a reason why the data
 needs processed as one block.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">There are other tricks I can try, but one obviously one is just to slim down the input. And fortunately there is some fat I can trim out of input datasets. But it seems that EEGlab deals with this by offering the option to mark data in
 continuous files as irrelevant, not by making a new copy of the dataset which just contains the data of interest. Is this correct?
<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Obviously I can write my own function to remove irrelevant sections from the dataset, but I just wanted to check that there wasn’t already some function out there first that chopped data out of EEG datasets.<u></u><u></u></p>

<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Thanks for any thoughts on this matter!<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Brent Field<u></u><u></u></p>
<p class="MsoNormal"> </p></div></div></blockquote></div><br></div></div>