Why can't I find the number 1.7?

Why does this return an empty answer for 1.7, but not 1.6 or 1.8? I am using an older version of Matlab (2006a), I have not tried this on a newer version yet.
test=0:0.1:5000;
>> find(test==1.7);
ans = Empty matrix: 1-by-0
>> find(test==1.8);
ans = 19
>> find(test==1.6)
ans = 17

4 件のコメント

Chris
Chris 2013 年 10 月 14 日
Update: I tried this in Matlab R2012b...same problem.
Kate
Kate 2013 年 10 月 14 日
I'm running a newer version of matlab and get the same error, so it's not your version. This makes so sense to me, sorry! 1.7 exists within test.
Jan
Jan 2013 年 10 月 14 日
This is not an error and it does not concern Matlab only, but this happens for other languages also in exactly the same way.
John D'Errico
John D'Errico 2013 年 10 月 14 日
This is a problem only to the extent that you don't understand floating point numbers and how they are stored. Time to read the FAQ.

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

回答 (2 件)

Carla
Carla 2013 年 10 月 14 日

1 投票

It's because your computer can't store decimal numbers in an exact form - there is always small but finite roundoff error in floating-point arithmetic. Have a look at this FAQ: http://matlab.wikia.com/wiki/FAQ
In particular, look at the section entitled "Why is 0.3 - 0.2 - 0.1 (or similar) not equal to zero?"
Yatin
Yatin 2013 年 10 月 14 日

0 投票

Hi,
It has to do with the way floating point numbers are represented in MATLAB. May be this article helps:

カテゴリ

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

質問済み:

2013 年 10 月 14 日

コメント済み:

2013 年 10 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by