counter = 1; posnx1 = 0; posny1 = 0; steps = 30; threshx = 0.5; threshy = 0.5; for i = 1:steps plot(posnx1,posny1,'o') set(gca,'XLim',[-15 15]) set(gca,'YLim',[-15 15]) F(i) = getframe; tmp = rand(2,1); if tmp(1,1) > threshx posnx1 = posnx1 + 1; else posnx1 = posnx1 - 1; end if tmp(2,1) > threshy posny1 = posny1 + 1; else posny1 = posny1 - 1; end end