フィルターのクリア

How to find vector components limiting a value?

2 ビュー (過去 30 日間)
osminbas
osminbas 2012 年 4 月 2 日
Hello,
Say A=[2;4;7;9;11;15].
How do you find the components (indices) of A which are limiting a value, say k=10?
In this case, it is easy to see that A(4) and A(5) are the limiting components, i.e, k is in between 9 and 11: A(4)<k<A(5). My actual A is much bigger.
Thanks!

採用された回答

the cyclist
the cyclist 2012 年 4 月 2 日
If your vector is guaranteed to be in sorted order, as in your example, then
max(find(a<k))
and
min(find(a>k))
will give the two limits.
You might want to make one of those include the equality, in case it might be exactly equal to the border. Also, you really only need to calculate, say, the lower limit, and then the other limit is just the next index.
Finally, you might need to consider what to do if all values in the vector are above (or below) the value of k.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by