count values in interval
17 次查看(过去 30 天)
显示 更早的评论
I have 7901 g values I accumulated it in t as t(n+1)=g. I want to count no. of values which are greater than 60. I want to count it from (1 to 950)=950 count ,(1951 to 2950)=1000 count, (3951 to 4950)=1000 count, (5951 to 6950)=1000 count and accumulate it in A. then I want to count from (951 to 1950) =1000 count, (2951 to 3950)=1000 count, (4951 to 5990) =1000 count, (6951 to 7901) =951 count and accumulated it in B. here first interval is 950 then next are 1000 and last is 951 length. how to do it in less line code I can do it by counting each interval by using for loop for each interval but it requires more length code. how to to it by less lines (2 to 3 lines) code. how to do it for common i.e. if g values are 11901 or 13901
0 个评论
回答(2 个)
KSSV
2016-11-6
Let data be your array and you want to find/ count values lying in-between interval [a,b].
l = data(data>=a && data<= b) ;
count = length(l);
0 个评论
Image Analyst
2016-11-6
Try this
data = randi(100, 1, 7951);
lastIndex = length(data)
edges = [1, 951 : 1000 : 6950, lastIndex]
for k = 1 : length(edges)-1
k1 = edges(k);
k2 = edges(k+1) - 1;
thisChunk = data(k1:k2);
count(k) = sum(thisChunk > 60)
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Histograms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!