Storing values in a loop

2 Ansichten (letzte 30 Tage)
Prince Igweze
Prince Igweze am 4 Dez. 2019
Beantwortet: Bhaskar R am 4 Dez. 2019
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

Antworten (1)

Bhaskar R
Bhaskar R am 4 Dez. 2019
Already your 20000 iterations of the x is stored in the variable in x
and for the histogram use command as
hist(x)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by