Fast counting how many elements within several ranges
显示 更早的评论
Hello everybody! I wish to count how many elements there are in an array named Y that are within range (a;b], how many within range (b;c], how many within range (c,d],... and save each of these values in another array. I have written this code:
k = NaN*zeros(num_sub,1);
for i=2:(num_sub+1)
k(i-1) = sum(Y <= interval_bounds(i) & Y > interval_bounds(i-1));
end
where in interval_bounds I have stored values [a,b,c,d,...] and num_sub is the number of subintervals (which is equal to length(interval_bounds)-1).
Do you think there may be a faster way to do this? Perhaps without using a for cycle?
Thank you in advance!
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!