%% Create Markov Chain from Random Transition Matrix
% This example shows how to create a Markov chain object from a right-stochastic transition matrix that is randomly generated. Such a Markov chain is convenient for exploration and testing.
% Create a random Markov chain object containing five arbitrary states.

rng(1); % For reproducibility
numStates = 5;
mc = mcmix(numStates)

% mc is a dtmc object.
%
% Display the transition matrix and verify that the sum of every row is 1.

mc.P
sum(mc.P,2)

%
% Plot a digraph of the Markov chain. Indicate probabilities of transition by using edge colors.

figure;
graphplot(mc,'ColorEdges',true);

% Copyright 2012 The MathWorks, Inc.