Storing values in a loop
1 回表示 (過去 30 日間)
古いコメントを表示
plot of x does not give a normal distribution as expected, seems to be an error in my code
n = 20000;
x = zeros(n,1)
x(1) = Mint(1)
for j = 1:n-1
x_c = normrnd(x(j),25);
if rand > min(1,normpdf(x_c)/normpdf(x(j)))
x(j+1) = x_c;
else
x(j+1) = x(j);
end
end
0 件のコメント
回答 (1 件)
Bhaskar R
2019 年 12 月 4 日
Already your 20000 iterations of the x is stored in the variable in x
and for the histogram use command as
hist(x)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!