Home > data-import > supporting_functions > event_not_v2.m

event_not_v2

PURPOSE ^

This version can handle events that have overlapping or duplicate events

SYNOPSIS ^

function out = event_not_v2(event_data, time_period)

DESCRIPTION ^

This version can handle events that have overlapping or duplicate events
time_period is [onset offset]  
Author: Seth Foster

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function out = event_not_v2(event_data, time_period)
0002 %This version can handle events that have overlapping or duplicate events
0003 %time_period is [onset offset]
0004 %Author: Seth Foster
0005 
0006 %shorthand
0007 e = event_data;
0008 tp = time_period;
0009 
0010 %check if e is empty
0011 if isempty(e)
0012     out = [];
0013     return
0014 end
0015 
0016 %remove invalid events where t1 > t2
0017 invalid = e(:,2) - e(:,1);
0018 log = invalid <= 0;
0019 e(log,:) = [];
0020 
0021 %sort event data by first column in the case that it was not already sorted
0022 ee = sortrows(e, [1 2]);
0023 
0024 %switch columns and then shift 1st column down by one and fill in NaN
0025 ee = [ee(:,2) ee(:,1)];
0026 shiftee = [[NaN; ee(:,1)] [ee(:,2); NaN]];
0027 
0028 %remove invalid events where t1 > t2
0029 
0030 invalid = shiftee(:,2) - shiftee(:,1);
0031 log = invalid <= 0;
0032 shiftee(log,:) = [];
0033 
0034 %determine where time_period fits into data
0035 
0036 [~, i] = min(abs(shiftee(:,1) - tp(1)));
0037 [~, i2] = min(abs(shiftee(:,2) - tp(2)));
0038 
0039 shiftee(i-1,1) = tp(1);
0040 shiftee(i2+1,2) = tp(2);
0041 
0042 %remove invalid events where t1 > t2
0043 
0044 invalid = shiftee(:,2) - shiftee(:,1);
0045 log = invalid <= 0;
0046 shiftee(log,:) = [];
0047 
0048 out = shiftee;
0049 
0050 end

Generated on Tue 23-May-2017 20:00:55 by m2html © 2005