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 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!