Comparing two numbers by using IF in Matlab
古いコメントを表示
I want to compare two numbers (x, and y), if they are equal or not.
However, even if these two numbers are equal, if condition in Matlab does not recognize them as equal numbers.
How I can make if statement recognize these two numbers if they are equal?
x=10.^(0.1.*4);
y=2.5119;
if x == y
z=1
'equal'
else
z=2
'Not Equal'
end
採用された回答
その他の回答 (2 件)
Stephen Carter
2014 年 10 月 15 日
They are not equal:
>> format long
>> x
x =
2.511886431509580
>> y
y =
2.511900000000000
Image Analyst
2014 年 10 月 15 日
0 投票
See the FAQ for an explanation and some code to make it do what you want: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
カテゴリ
ヘルプ センター および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!