1

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);
4

1 回答 1

3

在适当的偏移量处将第一列转换为 1,将第二列转换为 -1;然后cumsum。

%% something like 
ts(eventTimes(:,1))=1; ts(eventTimes(:,2)+1)=-1; ts=cumsum(ts);
于 2013-01-03T20:42:39.083 回答