You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

咨询MATLAB中histogram函数默认自动分箱算法及实现文献

MATLAB histogram Auto-Binning Algorithm Details

Hey there, let's break down your questions about MATLAB's histogram function—super valid to dig into the details since the official docs are a bit quiet on the exact references and implementation.

1. What auto-binning algorithm does histogram use?

By default (since R2014b), MATLAB's histogram uses a practical hybrid approach built around the Freedman-Diaconis rule, with adjustments for edge cases like small datasets or data with zero spread. Here's the step-by-step breakdown:

  • First, it calculates the interquartile range (IQR) of your dataset.
  • Using the Freedman-Diaconis formula, it computes an initial bin width:
    binWidth = 2 * IQR / n^(1/3)
    where n is the total number of data points.
  • The number of bins is derived by dividing the data's total range (max(data) - min(data)) by this bin width, then rounded to a logical integer.
  • For edge scenarios:
    • If the IQR is zero (all data points are identical), it defaults to a single bin.
    • For small datasets, it may fall back to Sturges' rule (which uses ceil(log2(n) + 1) bins) to avoid overly sparse, hard-to-interpret bins.
    • It also tweaks bin edges to align with "clean" numerical values (like whole numbers) for readability, even if that means adjusting the exact bin count slightly.

2. What's the referenced literature for this algorithm?

While MATLAB's official docs don't explicitly cite sources, the core of the auto-binning logic comes directly from the Freedman-Diaconis rule, first published in:

Freedman, D., & Diaconis, P. (1981). On the Histogram as a Density Estimator L2 Theory. Zeitschrift für Wahrscheinlichkeitstheorie und Verwandte Gebiete, 57(4), 453-476.

MATLAB's implementation adds real-world engineering tweaks (like handling edge cases and refining bin edges for usability) on top of this foundational statistical method, which is why you won't see a direct one-to-one citation—they've adapted it to work smoothly across diverse data scenarios.


内容的提问来源于stack exchange,提问作者User2201

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:08:59