Find indice of floating point number in matrix

13 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by