Hello! I have a vector X with some elements, and I want to find the position p of the element of X whose value is as close as possible to a known value A. For example, X = [1, 4.5, 6, 3 ,2.8] and A=4.7. The position of the element in X whose value is as close as possible to A is p=2, since X(2)=4.5 . Is there a fast way to do this, maybe using the function 'find' ? Thank you very much

 採用された回答

Paul
Paul 2014 年 2 月 25 日

1 投票

[val,ind]=min(abs(X-A))
Where val is the distance and ind the index .

1 件のコメント

aurc89
aurc89 2014 年 2 月 26 日
Thnaks Paul!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

質問済み:

2014 年 2 月 25 日

コメント済み:

2014 年 2 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by