matlab中方差直方图,如何规范直方图在MATLAB?
abcd的PDF區(qū)域不是一個,這在很多評論中都是不可能的。 假設(shè)在這里做了很多答案
假設(shè)連續(xù)邊之間的距離恒定。
在pdf下的概率應(yīng)該是1.在直方圖()和hist()中,歸一化應(yīng)該以probability進(jìn)行Normalization ,而不是用pdf Normalization 。
圖1 hist()方法的輸出,圖2直方圖()方法的輸出
兩種方法的最大幅度不同,它提出hist()的方法存在一些錯誤,因?yàn)閔istogram()的方法使用標(biāo)準(zhǔn)規(guī)范化。 我假設(shè)hist()方法的錯誤是關(guān)于歸一化為部分pdf ,而不是完全的probability 。
代碼與hist()[棄用]
一些言論
首先檢查:如果手動設(shè)置Nbins sum(f)/N會給出1 。
pdf要求圖g bin( dx )的寬度
碼
%http://stackoverflow.com/a/5321546/54964 N=10000; Nbins=50; [f,x]=hist(randn(N,1),Nbins); % create histogram from ND %METHOD 4: Count Densities, not Sums! figure(3) dx=diff(x(1:2)); % width of bin g=1/sqrt(2*pi)*exp(-0.5*x.^2) .* dx; % pdf of ND with dx % 1.0000 bar(x, f/sum(f));hold on plot(x,g,'r');hold off
輸出在圖1中。
用直方圖代碼()
一些言論
首先檢查:a)如果用直方圖()的Normalization作為概率調(diào)整Nbins ,則sum(f)為1 ; b)如果沒有規(guī)范化手動設(shè)置Nbins則sum(f)/N為1。
pdf要求圖g bin( dx )的寬度
碼
%%METHOD 5: with histogram() % http://stackoverflow.com/a/38809232/54964 N=10000; figure(4); h = histogram(randn(N,1), 'Normalization', 'probability') % hist() deprecated! Nbins=h.NumBins; edges=h.BinEdges; x=zeros(1,Nbins); f=h.Values; for counter=1:Nbins midPointShift=abs(edges(counter)-edges(counter+1))/2; % same constant for all x(counter)=edges(counter)+midPointShift; end dx=diff(x(1:2)); % constast for all g=1/sqrt(2*pi)*exp(-0.5*x.^2) .* dx; % pdf of ND % Use if Nbins manually set %new_area=sum(f)/N % diff of consecutive edges constant % Use if histogarm() Normalization probability new_area=sum(f) % 1.0000 % No bar() needed here with histogram() Normalization probability hold on; plot(x,g,'r');hold off
圖2中的輸出和預(yù)期的輸出被滿足:面積1.0000。
Matlab:2016a
系統(tǒng):Linux Ubuntu 16.04 64位
Linux內(nèi)核4.6
總結(jié)
以上是生活随笔為你收集整理的matlab中方差直方图,如何规范直方图在MATLAB?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php存密码,php 登录验证的代码(基
- 下一篇: matlab的可视化视频,MATLAB的