Floating point numeric problem

조회 수: 1 (최근 30일)
Qian Feng
Qian Feng 2016년 12월 9일
댓글: Star Strider 2016년 12월 17일
I encounter a problem which I cannot understand.
a = 1.228269:0.000001:1.22828;
b = 1.228265:0.000001:1.22828;
ismember(a,b)
>> ismember(a,b)
ans =
1×12 logical array
0 1 0 1 1 1 1 1 1 1 1 1
It is clearly to see that the logical array is not compatible with the values in vectors a and b. An expert has suggested that this has to do with the floating point numerics, do anyone can explain what happened to this example and how to we circumvent it ? Thanks a lot !

채택된 답변

Star Strider
Star Strider 2016년 12월 9일
What happened is best explained in: Why is 0.3 - 0.2 - 0.1 (or similar) not equal to zero?
You can circumvent it using the ismembertol function (in R2015a and later versions).
  댓글 수: 4
Qian Feng
Qian Feng 2016년 12월 17일
Thanks for the exposition here.
Star Strider
Star Strider 2016년 12월 17일
Our pleasure.

댓글을 달려면 로그인하십시오.

추가 답변 (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