MATLAB: Relational operator == doesn’t work properly in some cases! codefloating pointMATLABnot a bug When I run this code: 1.1-1==0.1 I recieve this: ans = logical 0 I think it's not rational. Could somebody explain why I'm getting that result? Best Answer You are seeing the effects of floating-point approximation error. See for example: Why is 0.3 - 0.2 - 0.1 (or similar) not equal to zero? and Floating-Point Numbers. Related SolutionsMATLAB: If statements not executing as expected Please see the FAQ on this topic. MATLAB: Is it a bug You have encountered ‘floating-point approximation error’. See Floating-Point Numbers for an extended discussion. Also see colon for an explanation of how it calculates the numbers in your ‘v’ vector. Related QuestionRelational Operator with CounterVery simple ‘if’ statement with == operator not workingRelational operators == for more than 1 or 2 elementsRelational Operator doesn’t workWeird results with relational operation ==A simple “bug” in finding an element in an array using find()Are relational operators so slow in this case
Best Answer