How to get more precision in comparing Elements of Matrix
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Adam
am 21 Nov. 2017
Bearbeitet: Adam
am 21 Nov. 2017
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
Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!