Matlab function "mean" returns the exact same value for "uint16" and "double" values, not for single values
Show older comments
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
Accepted Answer
More Answers (2)
Andreas Goser
on 13 Apr 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
on 14 Apr 2011
0 votes
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!