Matlab function "mean" returns the exact same value for "uint16" and "double" values, not for single values
显示 更早的评论
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
采纳的回答
更多回答(2 个)
Andreas Goser
2011-4-13
0 个投票
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!