Given some events and some time stamps, find which event contains each stamp USAGE: find_event_indices(EVENTS, TIMESTAMPS) What's returned is the index in the events list, i.e. the row number, for each time stamp. If there are no matches, returns 0 for that timestamp. There is more than one match, returns the index of the LAST match.

0001 function [indices] = find_event_indices(events, timestamps) 0002 % Given some events and some time stamps, find which event contains each stamp 0003 % USAGE: 0004 % find_event_indices(EVENTS, TIMESTAMPS) 0005 % 0006 % What's returned is the index in the events list, i.e. the row number, for 0007 % each time stamp. 0008 % 0009 % If there are no matches, returns 0 for that timestamp. 0010 % There is more than one match, returns the index of the LAST match. 0011 % 0012 % 0013 0014 indices = zeros(length(timestamps),1); 0015 0016 for i = 1 : length(timestamps) 0017 for j = 1 : size(events,1) 0018 if (timestamps(i)>= events(j,1)) && (timestamps(i) <=events(j,2)) 0019 indices(i) = j; 0020 end; 0021 0022 end; 0023 end; 0024 0025

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