image thumbnail
from Essential MATLAB by Brian Hahn
Companion software for Essential MATLAB for Scientists and Engineers

ant.m
f = zeros(1,100);
x = 40;           
                 
for i = 1:1000    
 r = rand;       
 if r >= 0.5     
   x = x + 1;    
 else            
   x = x - 1;    
 end             
 f(x) = f(x) + 1;
end               

Contact us at files@mathworks.com