randomwalk

Create a random walk in any number of dimensions
473 Downloads
Updated 1 May 2018

View License

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
Created with R2017b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Random Number Generation in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0.0