how to find the equality of 2 numbers?
조회 수: 2 (최근 30일)
이전 댓글 표시
a e
1 1
1 2
3 2
3 2
The above is my input table. Check 'a' for the value '1'. The corresponding 'e' value differs. So, we should not consider it. Check 'a' the value of '3'. The corresponding 'e' values are same. How to develop code for this?
댓글 수: 5
Image Analyst
2012년 9월 10일
Then see my answer. Also, what does "class(a)" show when you issue that command? If you want to make absolutely sure a and e are integers, wrap them in an int32() when you create them.
Walter Roberson
2012년 9월 10일
Please retag this question; see http://www.mathworks.co.uk/matlabcentral/answers/43073-a-guide-to-tags
채택된 답변
추가 답변 (3개)
Adrian Dronca
2012년 9월 10일
I think you should consider using isequal() . The function works with single, double, string.
댓글 수: 0
Image Analyst
2012년 9월 10일
If they're integers, use ==, like
if a == e
if they're floating point, you need to check against a tolerance:
if abs(a-e) < 0.0001
See the FAQ for more info: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!