2014-10-03 32 views
0

直方圖我有一個直方圖正火在Matlab

hist(A, 801) 

當前類似於正常曲線但在y = 1500的最大值,並將在x = 0.5的意思。我想它正常化,所以我嘗試

h = hist(A, 801) 
h = h ./ sum(h) 
bar(h) 

現在我得到,最大一個正常的曲線爲y = 0.03,但在x = 450

我怎麼降低頻率,所以平均總和是1,同時保留相同的x範圍?

A從

A = walk(50000, 800, .05, 2, .25, 0) 

衍生其中

function [X_new] = walk(N_sim, N, mu, T, sigma, X_init) 

delt = T/N; 
up = sigma*sqrt(delt); 
down = -sigma*sqrt(delt); 

p = 1./2.*(1.+mu/sigma*sqrt(delt)); 

X_new = zeros(N_sim,1); 
X_new(1:N_sim,1) = X_init; 

ptest = zeros(N_sim,1); 

for i = 1:N 

    ptest(:,1) = rand(N_sim,1); 
    ptest(:,1) = (ptest(:,1) <= p); 

    X_new(:,1) = X_new(:,1) + ptest(:,1)*up + (1.-ptest(:,1))*down; 

end 

回答

2

總和是1與您的代碼,因爲它代表。

你可能想要積分等於1(這樣你就可以與理論pdf進行比較)。在這種情況下:

[h, c] = hist(A, 801); %// c contains bin centers. They are equally spaced 
h = h/sum(h)/(c(2)-c(1)); %// normalize to area 1 
trapz(c,h) %// compute integral. Should be approximately 1 
+0

trapz(C,H)爲1,但是當我試圖用棒(C,H),以繪製它的最大值是圍繞y = 45 – 2014-10-03 15:12:23

+0

你需要更具體。爲什麼最大值在y = 45時有問題?你能提供重現你問題的數據嗎? – 2014-10-03 15:26:39

+0

我想讓曲線下的總和爲1 – 2014-10-03 16:23:29