天天看点

Matlab生成归一化直方图

使用matlab的函数histogram可以直接得到数据的直方图,但这并不是归一化的直方图。

使用如下代码可以得到归一化的直方图

x = randn(, );
numOfBins = ;
[histFreq, histXout] = hist(x, numOfBins);
binWidth = histXout()-histXout();
figure;
bar(histXout, histFreq/binWidth/sum(histFreq));       
xlabel('x');
ylabel('PDF: f(x)');
hold on
% fit a normal dist to check the pdf
PD = fitdist(x, 'normal');
plot(histXout, pdf(PD, histXout), 'r');
           

结果示意:

Matlab生成归一化直方图

继续阅读