Matlab is not recognizing that two floats are equal although Workspace shows they are
1 次查看(过去 30 天)
显示 更早的评论
```
% calculate_line_lengths
line_lengths = calculate_line_lengths(plane_x,plane_y, rect_corners);
% send the above two answers to herons_formula, get 4 areas
four_areas = herons_formula(edge_lengths, line_lengths);
sum_four_areas = sum(four_areas);
if sum_four_areas == rect_area
in_rect = true;
elseif sum_four_areas < rect_area
in_rect = false;
end
```
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/898755/image.png)
My code falls into the elseif when it should be going into the if statement as they are equal.
Why?
6 个评论
Jan
2022-2-18
@Walter Roberson: Until today, the method ismembertol has implemented the tolerance, did never match my needs in real code:
abs(u-v) <= tol*max(abs([A(:);B(:)]))
'DataScale' is not a solution also.
回答(1 个)
Prateek Rai
2022-2-24
You can refer to following MATLAB Answers on Why two equal numbers are not equal? to get more idea on why MATLAB is not recognizing that two floats are equal although workspace shows that they are equal.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!