Question on number accuracy and indexing

hi all, here is my problem. In the following code, I first give sigma an array from 0 to 1 with a step of 0.01. However, if I try to retrieve some value from it by indexing in the following code, I get '5.600000000000001e-01' for the first equation and an 'Empty matrix: 1-by-0' for the second. I know this must be related with the floating-point accuracy, but how can I avoid the empty matrix?
sigma=[0:0.01:1];
sigma(sigma==0.56)
sigma(sigma==0.57)

 採用された回答

Matt Fig
Matt Fig 2011 年 5 月 19 日

0 投票

This is the old Floating Point FAQ. Pay particular attention to the section where using a tolerance is discussed.

1 件のコメント

Guang
Guang 2011 年 5 月 20 日
thanks for the reference.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

質問済み:

2011 年 5 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by