Matlab中函数模式的问题
我在 Matlab 中有一个名为 example 的双数组,如下所示:
sample = ...
[0.4375 0.3750 0.5313 0.4375 0.8750 0.3750 0.5313 0.6563 0.3750 0.4375 ...
0.5313 0.5313 0.8438 0.8438 0.4375 0.5313 0.5313 0.5313 0.4375 0.3750 ...
0.4375 0.3750 0.3750 0.5313 0.3750 0.8750 0.5313 0.8438 0.4375 0.0313 ...
0.3750 0.8438 0.8438 0.3750 0.8750 0.8750 0.5313 0.4375 0.8750 1.7813 ...
0.3750 0.8750 0.3750 0.3750 0.3750 0.4375 0.3750 0.3750 0.8750 0.3750];
whos sample
Name Size Bytes Class Attributes
sample 1x50 400 double
问题是 mode(sample) 给我的结果为零,这显然是不正确的。
I have a double array named sample in Matlab as shown below:
sample = ...
[0.4375 0.3750 0.5313 0.4375 0.8750 0.3750 0.5313 0.6563 0.3750 0.4375 ...
0.5313 0.5313 0.8438 0.8438 0.4375 0.5313 0.5313 0.5313 0.4375 0.3750 ...
0.4375 0.3750 0.3750 0.5313 0.3750 0.8750 0.5313 0.8438 0.4375 0.0313 ...
0.3750 0.8438 0.8438 0.3750 0.8750 0.8750 0.5313 0.4375 0.8750 1.7813 ...
0.3750 0.8750 0.3750 0.3750 0.3750 0.4375 0.3750 0.3750 0.8750 0.3750];
whos sample
Name Size Bytes Class Attributes
sample 1x50 400 double
The problem is that mode(sample) gives me zero as a result and this obviously is not correct.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(这并不是真正的答案,但超出了我在评论中所能容纳的范围。)
我对此很了解,很可能是问题,或者您以某种方式重载了
mode
命令。尝试哪种模式
、清除模式
或只是重新启动Matlab。我无法重现,如下所示:
如果我添加小的随机数,我可以更改答案......但不能将其设置为零。
看起来您介于两者之间,因为您的
length(unique(sample))
返回了 12。作为参考,我得到(This is not really an answer, but more than I can fit in a comment.)
I'm with gnovice on this, most likely problem or that you have overloaded the
mode
command somehow. Trywhich mode
,clear mode
or just restarting Matlab.I cannot reproduce, as shown below:
If I add small random numbers, I can change the answer ... but not set it to zero.
It looks like you are somewhere between, since your
length(unique(sample))
returned 12. For reference, I get正如 MATLAB 文档明确指出的那样,“众数函数对于离散或粗略舍入的数据最有用。连续概率分布的众数被定义为其密度函数的峰值。将众数函数应用于该分布的样本不太可能提供对峰值的良好估计;最好计算直方图或密度估计并计算该估计的峰值。”
这并不能解释为什么您得到 0 结果,但它应该警告您不要依赖
mode
命令来获取浮点数据。我想知道如果将sample
变量中的值转换为整数并应用mode
命令,您会得到什么。As MATLAB documentation clearly states "the mode function is most useful with discrete or coarsely rounded data. The mode for a continuous probability distribution is defined as the peak of its density function. Applying the mode function to a sample from that distribution is unlikely to provide a good estimate of the peak; it would be better to compute a histogram or density estimate and calculate the peak of that estimate."
This doesn't explain why you are getting 0 as a result, but it should caution you not to rely on the
mode
command for floating point data. I wonder what you would get if you turned the values in thesample
variable into integers and apply themode
command.