Matlab function "mean" returns the exact same value for "uint16" and "double" values, not for single values
Afficher commentaires plus anciens
Hello,
I'm using Matlab 2010b. I noticed that mean(s) and mean(double(s)) return the same value whereas mean(s) and mean(single(s)) does not. Why?
s = uint16(2^16*rand(1000,1));
mean(s)==mean(double(s))
mean(s)==mean(single(s))
Thank you for your help. Stéphane
Réponse acceptée
Plus de réponses (2)
Andreas Goser
le 13 Avr 2011
0 votes
The issue in the code you use is not in MEAN, but in ==.
mean(double(s)) and mean(single(s)) return similar results, but not identical. And the reason is simply the nature of the data precision. It is not practical to write code that uses == in such case. But maybe you just used this code as an example for this posting. More info in this solution document.
Stéphane
le 14 Avr 2011
0 votes
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!