Info

この質問は閉じられています。 編集または回答するには再度開いてください。

which two members from s vector restricted a random number

2 ビュー (過去 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