so I need to create a function that plots location versus time for an individual who makes successive random jumps. Each jump is one unit to the right with probability R, and otherwise its one unit to the left. The arguments need to be R = probably of jumping one unit to the right; a = the initial location; and numjumps = number of jump the individual makes. I also need to use the
binornd() function.
What I've coded so far is:
function plot_sim(a,numjumps,R)
loc = a;
time = 0;
for i = 1:numjumps;
loc = loc + (2*binornd(1,R)-1);
time = time + 1;
hold on;
plot(time,loc,'-')
end
And I have to evaluate it with plot_sim(0,25,0.5). And I am just confused because even though I have plot(time,loc,'-'), it doesn't plot as connecting lines, it just plots as separate dots. I've tried including the plot function outside of the for loop and that doesn't work. I've even tried changing the colours of the dots and that doesn't even work. Am I coding this wrong?

답변 (1개)

Image Analyst
Image Analyst 2015년 4월 11일

1 개 추천

I have two random walk programs, both attached. Study each and adapt as needed.

카테고리

도움말 센터File Exchange에서 Random Number Generation에 대해 자세히 알아보기

질문:

2015년 4월 11일

답변:

2015년 4월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by