I have a Mx2
matrix, named events
where each row contains the onset and offset times of non-overlapping events. I'd like to construct a continuously sample signal that is equal to 1 for all points that are contained without any of the event times. I know the timestamps at which I'd like to sample my signal.
For example given the two variables eventTimes
and ts
:
eventTimes = ...
[1 3;
6 7;
9 10];
ts = 1:10;
The resulting binary signal would be
binarySignal = [1 1 1 0 0 1 1 0 1 1];
Current I solve this problem using anonymous function and closures, but its slow for very large data sets:
tmpFun = @(x) (x>=eventsTimes(:,1) & x<eventTimes(:,2));
binarySignal = cell2mat( arrayfun(tmpFun, ts, 'UniformOutput', 0) );
binarySignal = sum(binarySignal);