%% Visualize Evolution of State Distribution
% Create a four-state Markov chain from a randomly generated transition matrix containing eight infeasible transitions.

rng('default'); % For reproducibility 
mc = mcmix(4,'Zeros',8);

% mc is a dtmc object.
%
% Plot a digraph of the Markov chain.

figure;
graphplot(mc);

% State 4 is an absorbing state.
%
% Compute the state redistributions at each step for 10 discrete time steps. Assume an initial uniform distribution over the states.

X = redistribute(mc,10)

% X is an 11-by-4 matrix. Rows correspond to time steps, and columns correspond to states.
%
% Visualize the state redistribution.

figure;
distplot(mc,X)

% After 10 transitions, the distribution appears to settle with a majority of the probability mass in state 4.
% Copyright 2012 The MathWorks, Inc.