フィルターのクリア

Issue with find()

1 回表示 (過去 30 日間)
David
David 2016 年 9 月 14 日
コメント済み: David 2016 年 9 月 14 日
Hello,
I have something that seems to be quite a fundamental issue yet I am having issues fixing it:
I have an array containing various values, and I wish to find where in the array matches a value, which is caclulated eslewhere in the script.
Yet when using find() I'm getting some funny behaviour, as say I know one of the values is 0.65, and the variable containing 0.65 is called ratio_x, using
x = find(array == ratio_x)
returns an empty matrix, yet when using the value itself such as
x = find(array == 0.65)
it works fine.
Both array and ratio_x are saved as double, and array is rounded to 2 decimal places.
Any help would be appreciated.

採用された回答

KSSV
KSSV 2016 年 9 月 14 日
It is not advised to compare floating point numbers using ==. You have to fix a small number (tolerance) say, eps = 10^-5 and check for is the absolute difference less then that. If so then the floating point numbers are close enough. '
More on:
  1 件のコメント
David
David 2016 年 9 月 14 日
That works fine too, thank you very much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by