如何在matlab中将 bin 中心转换为 bin 边?

2025-10-10 02:30:05

1、例如,指定 bin 中心以用于 hist。这些 bin 具有均匀的宽度。

命令行键入:

A = [-9 -6 -5 -2 0 1 3 3 4 7];

如何在matlab中将 bin 中心转换为 bin 边?

2、命令行键入:

centers = [-7.5 -2.5 2.5 7.5];

如何在matlab中将 bin 中心转换为 bin 边?

3、命令行键入:

hist(A,centers)

如何在matlab中将 bin 中心转换为 bin 边?

4、要将 bin 中心转换为 bin 边界,请计算 centers 中各连续值之间的中点。此方法会重现均匀和非均匀 bin宽度对应的 hist 结果。

命令行键入:

d = diff(centers)/2;

如何在matlab中将 bin 中心转换为 bin 边?

5、命令行键入:

edges = [centers(1)-d(1), centers(1:end-1)+d, centers(end)+d(end)];

如何在matlab中将 bin 中心转换为 bin 边?

6、hist 函数包括落入每个 bin 右边界上的值(第一个 bin 包含两个边界),而 histogram 包括落入每个bin 左边界上的值(最后一个 bin 包含两个边界)。稍微移动 bin 边界以获得与 hist 相同的 bin 计数。

命令行键入:

edges(2:end) = edges(2:end)+eps(edges(2:end))

如何在matlab中将 bin 中心转换为 bin 边?

7、现在,将 histogram 与 bin 边界结合使用。

命令行键入:

histogram(A,edges)

如何在matlab中将 bin 中心转换为 bin 边?

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢