How to get more precision in comparing Elements of Matrix

2 visualizzazioni (ultimi 30 giorni)
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 Commento
Adam
Adam il 21 Nov 2017
Modificato: Adam il 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

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by