Count number of occurrences in each second.

7 次查看(过去 30 天)
I'm trying to create a script which counts the number of occurrences of an event each second.
For example I receive data such as below and this is when something has been triggered in seconds.
1.1, 1.2, 1.5, 1.9, 2, 2.5, 2.9.
I want to know what code would tell me how many times the event occurred between 1-2 seconds, 2-3 seconds etc. There are potentially around 2000 seconds to do this for. So for 1-2 seconds I would expect to see a count of 4. For 2-3 seconds I would expect to see a count of 3.
Many Thanks
  4 个评论
KSSV
KSSV 2020-6-5
Not clear..you need expalin more about your data.
Nick Storr
Nick Storr 2020-6-5
Ok. My data is essentially when beta brainwaves occur. So the trials took between 20 minutes and 30 minutes. When the beta brain wave band is reached it will say it took 9.6 seconds from the start of the trial.
It will then give me an array of times that beta was met, creating a vector. I want to know how many times beta was reached in each 'second' in that vector. Whilst the number represents seconds it is essentially a just a number and doesn't doesn't include time stamps or any other information which needs transforming.
So if beta was present at 1.2 and 1.4 it would show that there were 2 numbers present between 1 and 2.
Does this help? Happy to provide more information.
Many Thanks
Nick

请先登录,再进行评论。

采纳的回答

madhan ravi
madhan ravi 2020-6-5
编辑:madhan ravi 2020-6-5
x = [1.1, 1.2, 1.5, 1.9, 2, 2.5, 2.9];
u = unique(fix(x));
Counts = arrayfun(@(y) nnz(x>=y & x<(y+1)), u)
%or
Counts = sum((x>=u.') & (x<(u.'+1)),2)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by