Home > data-analysis > manip > cevent > ruj_cevent2cstream.m

ruj_cevent2cstream

PURPOSE ^

Convert event to cstream given a range of time

SYNOPSIS ^

function cstream = cevent2cstream(event, times, default)

DESCRIPTION ^

 Convert event to cstream given a range of time
 cstream = event2cstream(event, times)
 Output is a binary in the cstream form.  The input event is assumed to be
 sorted and not overlapped.
 The input TIMES should be a MATLAB range expression, for instance
 1:0.1:35.  Or it could be any sorted list of timestamps.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function cstream = cevent2cstream(event, times, default)
0002 % Convert event to cstream given a range of time
0003 % cstream = event2cstream(event, times)
0004 % Output is a binary in the cstream form.  The input event is assumed to be
0005 % sorted and not overlapped.
0006 % The input TIMES should be a MATLAB range expression, for instance
0007 % 1:0.1:35.  Or it could be any sorted list of timestamps.
0008 
0009 if ~exist('default', 'var')
0010     default = 0;
0011 end
0012 
0013 if size(event, 2) == 2
0014     event(:, 3) = 1;
0015 end
0016 
0017 
0018 % change to account for empty events
0019 if size(event,1) == 0
0020     event_count = 0;
0021     start = 0;
0022     stop=0;
0023 else
0024     event_count = 1;
0025     start = event(1,1);
0026     stop = event(1,2);
0027 end
0028 
0029 total = length(times);
0030 cstream = zeros(total,2);
0031 cstream(:,1) = times;
0032 cstream(:,2) = default;
0033 total_event = size(event, 1);
0034 
0035 % For each time
0036 for i = 1:total
0037     time = times(i);
0038     
0039     % if this time is past the stop of the event, search for a new event.
0040     while(time >= stop && event_count < total_event)
0041         event_count = event_count + 1;
0042         start = event(event_count ,1);
0043         stop = event(event_count ,2);
0044     end
0045 
0046     % Check if before event
0047     if(time < start)
0048         cstream(i,2) = 0;
0049     elseif (time < stop) % not before.  During?
0050         cstream(i,2) = event(event_count, 3);
0051     else % Not before or during.  After.
0052         % This should only happen when we've run out of events.
0053         assert(event_count == total_event);
0054         % The rest of the variable should be zeros, which it already is.
0055         % We're done!
0056         break
0057     end
0058 end
0059 end

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