MATLAB: Detecting no. of events

adscript

I have an array of 2000×1 = D .
i have a condition D>25. for D>25 higher than 20 sec i should count 1 event.
how can i do this in matlab?

Best Answer

If D contains an entry every second, you can use:
D = randi(2000, 1, 20); % sample data
di = diff([0 D > 25 0]);
i1 = find(di == 1);
i2 = find(di == -1);
Nevents = nnz(i2 - i1 > 20);