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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by