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!