Extract values within a range in a for loop

조회 수: 13 (최근 30일)
Sesilia Iileka
Sesilia Iileka 2019년 3월 7일
댓글: Walter Roberson 2019년 3월 8일
I have a loop like this:
for i = 1:length(x)
xy = find(u==i | u>i & u<(i+1)); #xy should find indices of u within that range i.e u(i)>=i<u(i+1)
N(i) = length(xy) #giving me counts of i
end
but then, the last iteration (last value of i) will be wrong by this expression.
how do i correct this please?
Or any better suggestion (function) by which I can do this
Thanks a lot

채택된 답변

Walter Roberson
Walter Roberson 2019년 3월 7일
histcounts or the older histc.
Note that the two functions have different results for values that are exactly equal to the last element of the vector of bins. histc uses a separate bin for values exactly equal to the last bin but histc makes it part of the previous bin.
  댓글 수: 4
Sesilia Iileka
Sesilia Iileka 2019년 3월 8일
This code has errors Roberson. Please check it again. Thanks
Walter Roberson
Walter Roberson 2019년 3월 8일
it worked when I tested it using appropriate edge information where I wrote the .... in the outline . however I was confused about which array had the edge information and which had the data to be partitioned.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by