if I have a list of numbers and I want to know where a number lies between two numbers in that list.

댓글 수: 2

Roger Stafford
Roger Stafford 2016년 12월 19일
Please give more details in your question! Better still, give a concrete example of the "list" and precisely what results you wish to obtain from it.
khamiis E
khamiis E 2016년 12월 19일

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

 채택된 답변

Guillaume
Guillaume 2016년 12월 19일

1 개 추천

A = [10 25
30 45
50 150
300 450
500 501
502 600
630 700
720 800
801 815
820 1000];
B = 33;
find(B >= A(:, 1) & B <= A(:, 2))

추가 답변 (2개)

Walter Roberson
Walter Roberson 2016년 12월 19일

1 개 추천

Suppose you have a vector of values in sorted order, and have some other values, and you want to know where in the vector the other values would sit. Then:
[~, ~, binnumber] = histcounts(TheOtherValues, TheVectorOfFixedValues);
Then, TheOtherValues(K) is between TheVectorOfFixedValues(binnumber(K)) and the next value.

댓글 수: 5

khamiis E
khamiis E 2016년 12월 19일
편집: khamiis E 2016년 12월 19일
Thanks alot for your answer. I can't find the histcounts() function. Is there alternative function?
Star Strider
Star Strider 2016년 12월 19일
The previous histcounts function was called histc with a slightly different calling and output syntax.
Walter Roberson
Walter Roberson 2016년 12월 19일
[~, binnumber] = histc(TheOtherValues, TheVectorOfFixedValues);
Walter Roberson
Walter Roberson 2016년 12월 19일
Note: this code was written assuming that your ranges had no gaps, but it appears from your diagram that it does not apply.
khamiis E
khamiis E 2016년 12월 20일
I really appreciate your effort . thanks for your time and your answer

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

Andrei Bobrov
Andrei Bobrov 2016년 12월 19일
편집: Andrei Bobrov 2016년 12월 19일

1 개 추천

A = [10 25
30 45
50 150
300 450
500 501
502 600
630 700
720 800
801 815
820 1000]; % your "start-end"
B = [33 300 501 75 754 809 1000 47]'; % Let B - your numbers
b = prod(A - reshape(B,1,1,[]),2);
out = sum(bsxfun(@times,squeeze(b < 0 | b == 0),(1:size(A,1))'))

댓글 수: 1

khamiis E
khamiis E 2016년 12월 20일
I really appreciate your effort . Thanks for your answer.

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

카테고리

도움말 센터File Exchange에서 Variables에 대해 자세히 알아보기

태그

질문:

2016년 12월 19일

댓글:

2016년 12월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by