P=0; % Starting value
for i=1:10 % i is the number of steps from 1 to 10
R=rand; if R<0.5 S=-1; elseif R>0.5 S=1;end P=S+P % Gives the next random walk from the new position P every time
endxlabel('Position')ylabel('Step Count')title('1-D Random Walk')
MATLAB: How to plot a 1-d random walk that generate 1 and -1 with equal probability? I am struggling to plot every individual P that I get against i the number of step.
random walk
Best Answer