Home > data-utility > granger_causality > gcause_libs > event2point_process.m

event2point_process

PURPOSE ^

Convert events to cstream with only its onsets or offsets given a range of time

SYNOPSIS ^

function cstream = event2point_process(events, times, point_select)

DESCRIPTION ^

 Convert events to cstream with only its onsets or offsets given a range of time
 cstream = event2cstream(events, times)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function cstream = event2point_process(events, times, point_select)
0002 % Convert events to cstream with only its onsets or offsets given a range of time
0003 % cstream = event2cstream(events, times)
0004 
0005 total = length(times);
0006 
0007 if isempty(events)
0008     cstream = zeros(total,2);
0009     cstream(:,1) = times;
0010     return;
0011 end
0012 
0013 if strcmp(point_select, 'onset')
0014     events(:, 2) = events(:, 1) + eps;
0015 elseif strcmp(point_select, 'offset')
0016     events(:, 1) = events(:, 2);
0017     events(:, 2) = events(:, 2) + eps;
0018 else
0019     error('The value of POINT_SELECT can only be ''onset'' or ''offset''.');
0020 end
0021 
0022 if size(events, 2) == 2
0023     events(:, 3) = 1;
0024 end
0025 
0026 event_count = 1;
0027 start = events(1,1);
0028 
0029 cstream = zeros(total,2);
0030 cstream(:,1) = times;
0031 total_event = size(events, 1);
0032 
0033 % For each time
0034 for i = 1:total
0035     time = times(i);
0036     
0037 %     % if this time is past the stop of the events, search for a new events.
0038 %     while(time > stop && event_count < total_event)
0039 %         event_count = event_count + 1;
0040 %         start = events(event_count ,1);
0041 %     end
0042 
0043     % Check if before events
0044     if(time < start)
0045         cstream(i,2) = 0;
0046     else
0047         cstream(i,2) = 1;
0048         event_count = event_count + 1;
0049         
0050         if event_count > total_event
0051             break;
0052         end
0053         
0054         start = events(event_count ,1);
0055     end
0056 end
0057 end

Generated on Tue 23-May-2017 03:00:58 by m2html © 2005