How to get more precision in comparing Elements of Matrix

2 次查看(过去 30 天)
I have a double matrix and i want to pick up the largest element in each column . I found out that Matlab compares only ith 4 numbers after the point , that's what actually matlab shows in the variables window. By changing the Format in the comand windows i get this :
format long
ans =
0.001016470327852
ans =
0.001024700640374
But Matlab is only comparing 0.0010 and considering them equal ...
Thank you in advance
  1 个评论
Adam
Adam 2017-11-21
编辑:Adam 2017-11-21
Matlab uses the complete number for maths. How it is formatted for visualisation is irrelevant. If you need the difference to a high number of decimal places then that is different, but up to double precision the maths is precise for comparing equality or greater than operations.
>> a = 0.001016470327852
a =
0.001016470327852
>> b = 0.001024700640374
b =
0.001024700640374
>> a == b
ans =
logical
0
>> b > a
ans =
logical
1

请先登录,再进行评论。

回答(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