Find indice of floating point number in matrix
12 次查看(过去 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
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!