Search closest value in a vector

search value in sorted vector and find index and value with respect to vector that is equal or clos
ダウンロード: 14.1K
更新 2009/7/9

ライセンスの表示

Search value 'v' in sorted vector 'x' and find index and value
with respect to vector x that is equal or closest to 'v'.

If more than one value is equal then anyone can be returned
(this is property of binary search).
If more than one value is closest then first occurred is returned
(this is property of linear search).

Algorithm
First binary search is used to find v in x. If not found
then range obtained by binary search is searched linearly
to find the closest value.

INPUT:
x: vector of numeric values,
x should already be sorted in ascending order
(e.g. 2,7,20,...120)
v: numeric value to be search in x

OUTPUT:
i: index of v with respect to x.
cv: value that is equal or closest to v in x

引用

Dr. Murtaza Ali Khan (2024). Search closest value in a vector (https://www.mathworks.com/matlabcentral/fileexchange/15088-search-closest-value-in-a-vector), MATLAB Central File Exchange. 取得済み .

MATLAB リリースの互換性
作成: R14SP2
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
カテゴリ
Help Center および MATLAB AnswersOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!
バージョン 公開済み リリース ノート
1.1.0.0

BSD License

1.0.0.0