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

a791b137af350ceacee0c8f742126968.png

ITMISS

自2014b起,Matlab将这些规范化例程本机嵌入在histogram函数中(有关此函数提供的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;endmu = 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)在此处输入图片说明改进很可能归因于实际问题和接受的答案的成功!编辑-使用hist和histc被不建议现在,和histogram应改为使用。请注意,使用此新功能创建垃圾箱的6种方法均不会产生垃圾箱  hist并histc产生。有一个Matlab脚本可以更新以前的代码以适应  histogram调用方式(bin边而不是bin中心-link)。这样,可以比较pdf @abcd(trapz和sum)和Matlab(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 histbar(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)在此处输入图片说明新的PDF规范化与以前的规范化之间的最大差是5.5511e-17。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值