matlab中方差直方图,如何在MATLAB中标准化直方图?

从2014b开始,Matlab将这些标准化例程本机嵌入在pdf函数中(有关此函数提供的6个例程,请参阅帮助文件)。 这是一个使用PDF归一化的示例(所有bin的总和为1)。

data = 2*randn(5000,1) + 5; % generate normal random (m=5, std=2)

h = histogram(data,'Normalization','pdf') % PDF normalization

相应的PDF是

Nbins = h.NumBins;

edges = h.BinEdges;

x = zeros(1,Nbins);

for counter=1:Nbins

midPointShift = abs(edges(counter)-edges(counter+1))/2;

x(counter) = edges(counter)+midPointShift;

end

mu = mean(data);

sigma = std(data);

f = exp(-(x-mu).^2./(2*sigma^2))./(sigma*sqrt(2*pi));

两者一起给

hold on;

plot(x,f,'LineWidth',1.5)

9c49f165d85e1a1da6e3a321e44ac454.png

改进很可能归因于实际问题和接受的答案的成功!

编辑-现在不建议使用pdf和eps,应改用histogram。 请注意,使用此新功能创建垃圾箱的6种方法均不会产生垃圾箱hist和histc垃圾箱。 有一个Matlab脚本可以更新以前的代码,以适应histogram(调用箱边而不是箱中心-链接)的方式。 这样做可以比较@abcd(trapz和sum)和Matlab(pdf)的pdf归一化方法。

3 pdf归一化方法给出的结果几乎相同(在eps范围内)。

测试:

A = randn(10000,1);

centers = -6:0.5:6;

d = diff(centers)/2;

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

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

figure;

subplot(2,2,1);

hist(A,centers);

title('HIST not normalized');

subplot(2,2,2);

h = histogram(A,edges);

title('HISTOGRAM not normalized');

subplot(2,2,3)

[counts, centers] = hist(A,centers); %get the count with hist

bar(centers,counts/trapz(centers,counts))

title('HIST with PDF normalization');

subplot(2,2,4)

h = histogram(A,edges,'Normalization','pdf')

title('HISTOGRAM with PDF normalization');

dx = diff(centers(1:2))

normalization_difference_trapz = abs(counts/trapz(centers,counts) - h.Values);

normalization_difference_sum = abs(counts/sum(counts*dx) - h.Values);

max(normalization_difference_trapz)

max(normalization_difference_sum)

c8a6485de10ef70cf17d7447e150d3f9.png

新的PDF规范化与以前的规范化之间的最大差是5.5511e-17。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值