randomwalk
randomwalk - create random walk in arbitrary dimension
P = randomwalk(N, D) produces a N-by-D matrix P with the positions of a random walk of N steps in D dimensions, starting from (0,..,0). P(K,:) holds the coordinates of the position at step K. Each step from one position to the next is +1 or -1 along a random dimension.
With a third logical argument, randomwalk(N, D, true) creates a plot of the random walk in a new figure.
Examples:
P = randomwalk(2, 10) % -> for example
% P = [0 0 ; 1 0 ; 1 1 ; 2 1 ; 2 0 ; 2 -1 ; 3 -1 ; 3 -2 ; 2 -2 ; 2 -1]
randomwalk(1000,4,true) ; % create a plot
Cite As
Jos (10584) (2024). randomwalk (https://www.mathworks.com/matlabcentral/fileexchange/67160-randomwalk), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |