count values in interval

조회 수: 19 (최근 30일)
Jay Hanuman
Jay Hanuman 2016년 11월 6일
답변: Image Analyst 2016년 11월 6일
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

답변 (2개)

KSSV
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);

Image Analyst
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

카테고리

Help CenterFile Exchange에서 AUTOSAR Blockset에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by