登录论坛

查看完整版本 : 如何在MATLAB中标准化直方图?


poster
2019-12-14, 20:13
如何对直方图进行归一化,以使概率密度函数下的面积等于1?



回答:

我对此的回答与您对先前问题 (https://stackoverflow.com/questions/5303372/uniform-distribution-u0-1-normal-distribution-nmean-variance2-n-in-matla)的回答相同。对于概率密度函数, 整个空间的积分为1 (http://en.wikipedia.org/wiki/Probability_density_function) 。除以总和不会得到正确的密度。为了获得正确的密度,必须除以面积。为了说明我的观点,请尝试以下示例。

[f, x] = hist(randn(10000, 1), 50); % Create histogram from a normal distribution. g = 1 / sqrt(2 * pi) * exp(-0.5 * x .^ 2); % pdf of the normal distribution % METHOD 1: DIVIDE BY SUM figure(1) bar(x, f / sum(f)); hold on plot(x, g, 'r'); hold off % METHOD 2: DIVIDE BY AREA figure(2) bar(x, f / trapz(x, f)); hold on plot(x, g, 'r'); hold off 您可以自己查看哪种方法与正确答案(红色曲线)相符。

https://i.stack.imgur.com/cDdLG.png

标准化直方图的另一种方法(比方法2更直接)是除以sum(f * dx) ,它表示概率密度函数的积分,即

% METHOD 3: DIVIDE BY AREA USING sum() figure(3) dx = diff(x(1:2)) bar(x, f / sum(f * dx)); hold on plot(x, g, 'r'); hold off

更多&回答... (https://stackoverflow.com/questions/5320677)