Home > data-analysis > manip > event > event_expand.m

event_expand

PURPOSE ^

extends the end of each event to the beginning of the next one

SYNOPSIS ^

function expanded = event_expand(events, bounds)

DESCRIPTION ^

 extends the end of each event to the beginning of the next one

 event_expand(events)

 event_expand(events, bounds)

 The first form sets the end of each event to the beginning time of the
 next event, creating a continuous stream of events with no breaks.

 The second form does the same, but with the given bounds.  The bounds are
 boundaries across which the events are not expanded.  It's almost like
 applying (events AND bounds), but if an event was going to be expanded to
 be on both sides of the bounds, it will instead stop at the beginning of
 the bounds.

 The end time of the last event becomes Inf unless you supply bounds.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function expanded = event_expand(events, bounds)
0002 % extends the end of each event to the beginning of the next one
0003 %
0004 % event_expand(events)
0005 %
0006 % event_expand(events, bounds)
0007 %
0008 % The first form sets the end of each event to the beginning time of the
0009 % next event, creating a continuous stream of events with no breaks.
0010 %
0011 % The second form does the same, but with the given bounds.  The bounds are
0012 % boundaries across which the events are not expanded.  It's almost like
0013 % applying (events AND bounds), but if an event was going to be expanded to
0014 % be on both sides of the bounds, it will instead stop at the beginning of
0015 % the bounds.
0016 %
0017 % The end time of the last event becomes Inf unless you supply bounds.
0018 %
0019 
0020 inv_bounds = event_NOT(bounds, [-Inf Inf]);
0021 
0022 if nargin > 1
0023     % make bounds big enough to be added to events
0024     inv_bounds(:, 3:size(events, 2)) = NaN;
0025 
0026     [with_bounds, orig_indices] = sortrows(vertcat(events, inv_bounds));
0027     fake_rows = orig_indices > size(events, 1);
0028     
0029     work = with_bounds;
0030 else
0031     work = events;
0032 end
0033 
0034 % event end times come from beginning times of subsequent events
0035 new_end_times = vertcat(work(2:end, 1), Inf);
0036 work(:, 2) = new_end_times;
0037 
0038 % possibly restrict the result to be within the bounds.
0039 if nargin > 1
0040     work = work(~ fake_rows, :);
0041 end
0042 
0043 expanded = work;

Generated on Wed 24-May-2017 00:00:56 by m2html © 2005