MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   如何在MATLAB中标准化直方图? (https://www.labfans.com/bbs/showthread.php?t=26609)

poster 2019-12-14 20:13

如何在MATLAB中标准化直方图?
 
如何对直方图进行归一化,以使概率密度函数下的面积等于1?



[B]回答:[/B]

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

[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 您可以自己查看哪种方法与正确答案(红色曲线)相符。

[IMG]https://i.stack.imgur.com/cDdLG.png[/IMG]

标准化直方图的另一种方法(比方法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

[url=https://stackoverflow.com/questions/5320677]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 22:43

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.