How can I check which values in 2 matrices are identical?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dear all,
I have 2 matrices (attached) - as their name suggests, the 1st contains mean values while the 2nd contains trimmed means values. I am interested in finding out which means and trimmed means differ (upon eyeballing both arrays, lots of values seem identical, which makes sense to me since I'm trimming my data only ever so slightly). In order to do this, I've done this:
difference= means_IB-trimmean_IB;
distinction= find (d~=0);
However, upon eyeballing the difference matrix, I can't explain some values - for example,
means_IB(3,2)
ans =
-32.2740
trimmean_IB(3,2)
ans =
-32.2740
difference(3,2)
ans =
-1.4211e-14
I have a slight hunch the result of difference(3,2) has to do with decimal places not captured by the matrices but I don't think my intuition is right.
Would you please be so kind as to help me?
Thank you in advance, Bianca
3 commentaires
Jan
le 29 Mar 2017
You did not show yet, how this value is created. All we know, is that you got it from some calculations.
Réponses (1)
Jan
le 29 Mar 2017
Modifié(e) : Jan
le 29 Mar 2017
means_IB(3,2) - trimmean_IB(3,2)
% >> -1.4211e-14
This means, that this is the distance between the two values. An explanation of this effect would concern the calculation of trimmean_IB, but without seeing the corresponding code, it is hard to guess the details.
Most likely the routine for the trimming leads to different rounding "errors", which are not errors, but the effect of storing values in the double format with a limited precision. According to the "IEEE754 standard" doubles contain about 16 digits. In consequence arithmetic operations can differ by eps (see: doc eps) according to the order of the operations:
1 + 1e-17 - 1
1 - 1 + 1e-17
You can control (but not solve!) this by using a tolerance:
distinction= find(d > 10 * eps(means_IB));
The used limit depends on the problem.
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!