Matlab function "mean" returns the exact same value for "uint16" and "double" values, not for single values
Ältere Kommentare anzeigen
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
Akzeptierte Antwort
Weitere Antworten (2)
Andreas Goser
am 13 Apr. 2011
0 Stimmen
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
am 14 Apr. 2011
0 Stimmen
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!