필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

which two members from s vector restricted a random number

조회 수: 1 (최근 30일)
som
som 2012년 9월 3일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi all,
I have a vector like s=[200 278 434 590 746 903 1059 1215 1371 1450]. I want to determine which two members from s vector restricted a random number like b=300 ? for example 300 is between 278 and 434.
How can I write such program?
thanks in advance,

답변 (1개)

Jan
Jan 2012년 9월 3일
편집: Jan 2012년 9월 3일
s = [200 278 434 590 746 903 1059 1215 1371 1450];
b = 300;
[dummy, index] = histc(b, s);
Or:
index = find(s < b, 1, 'last'); % or <= ?
Because the values of s are sorted, it is enough to find one index.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by