How do I draw the graph of the same function several times?
Show older comments
clear clc
x_t(1) = 0;
N = 10^2;
for t = 1:N
xlabel('t'), ylabel('x_t'), title('Random Walk')
a = sign(randn);
x_t(t+1) = x_t(t) + a;
plot(x_t,'b-')
hold on
pause(0.05);
end
How do I plot this same function several times? This is a random walk, every time it gets plotted I want it to look differently, which is exactly what sign(randn) does.
2 Comments
KSSV
on 6 Oct 2017
randn generates normally distributed random numbers.
sign gives it sign..if positive +1 and if negative -1.
Delshad Ayoubi
on 6 Oct 2017
Edited: Delshad Ayoubi
on 6 Oct 2017
Accepted Answer
More Answers (0)
Categories
Find more on Parallel Computing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!