Find indice of floating point number in matrix

12 ビュー (過去 30 日間)
sparsh garg
sparsh garg 2021 年 9 月 6 日
コメント済み: sparsh garg 2021 年 9 月 6 日
Find method allows us to return the indice of a particular element in a matrix/array.
However when the matrix contains floating point values,find generally returns NUll array.
I tried using the following algorithm by adding tolerance but even that fails.
So now 2 questions why does find fail on floating point arrays and secondly how should I go about solving the problem
idx = find(abs(x-2.5)<1e-3);
X is enclosed as follows

採用された回答

Jan
Jan 2021 年 9 月 6 日
find() does not fail on floating point arrays. If a floating point array is provided, find replies the indices of all elements, which are not 0.
In your case you provide a logical array: abs(x - 2.5) < 1e-3
Then find() replies the indices of all elements, which have a distance of less than 1e-3 from 2.5. If the output is empty, there is no such element. This is not a failure, but the expected behavior.
The value with the smallest distance to 2.5 in your data set is 0.057631. The distance is larger than 1e-3, so your code works correctly.
  1 件のコメント
sparsh garg
sparsh garg 2021 年 9 月 6 日
ahh yes just tried it had to fill in the entire cumbersome value 92.2425 but in the end it worked.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by