Given the transition matrix M for a Markov chain and an initial state i0, the command randmarkov(M,i0,n) will generate a random walk (given as a vector) starting at i0 and taking n random steps, where each step is a transition with probabilities given by M. For example, if you enter
you might get
Alternatively, given a vector v = [n1,…,np], the command randmatrix(v,i0) will create a stochastic matrix with p recurrent loops (given by v) and i0 transient states. If you enter
you might get