【问题标题】:Understanding Matlab histcounts behavior了解 Matlab histcounts 行为
【发布时间】:2020-05-12 02:20:35
【问题描述】:
histcounts(1:100,'BinWidth',50)

返回

49    51

为什么不返回

50    50

改为?

【问题讨论】:

  • 可能是因为 bin 在网格点之间居中,所以你错过了 0 和 1 之间的 0.5 中心......你可能想要histcounts(0:99,'BinWidth',50)

标签: matlab histogram


【解决方案1】:

使用h = histogram(1:100, 'BinWidth', 50) 对 1 到 100 进行直方图分析得出:

让我们看看 bin 边缘:

h.BinEdges

ans =

     0    50   100

来自MATLAB's help

每个 bin 包括左边缘,但不包括右边缘, 除了包含两条边的最后一个 bin

这意味着值 1 到 100 以这种格式直方图:

Bin 1 => edges: [0 50) => Included values: [1, 2, 3, .., 49]         (n = 49)
Bin 2 => edges: [50 100] => Included values: [50, 51, 52, .., 100]   (n = 51)

histcount(X) 以与histogram(X) 相同的方式对X 进行分区。因此,结果是您应该期待的,实际上是非常合理的。

【讨论】:

    猜你喜欢
    • 2017-11-22
    • 2015-03-07
    • 2014-11-21
    • 1970-01-01
    • 2014-03-30
    • 2012-06-01
    • 2013-11-12
    • 1970-01-01
    • 2016-09-28
    相关资源
    最近更新 更多