%% Specify Structure for Random Markov Chain
% This example shows how to specify certain infeasible transitions and randomly distribute others within a transition matrix for a Markov chain.
% Create a six-state Markov chain from a random transition matrix. Plot its digraph and indicate transition probabilities by using edge colors.

rng(1); % For reproducibility
numStates = 6;
mc1 = mcmix(numStates);

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

% mcmix produces a Markov chain such that all states are persistent and all states are reachable from any other state.
%
% Create another six-state Markov chain, but without any persistent states and with 12 other infeasible transitions in random locations in the transition matrix.

Fix = ones(numStates) - eye(numStates);
Fix(Fix == 1) = NaN;
zeros = 12;
mc2 = mcmix(numStates,'Zeros',zeros,'Fix',Fix);

%
% Display the transition matrix of mc2. Plot a digraph of mc2 and indicate transition probabilities by using edge colors.

mc2.P

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

% Copyright 2012 The MathWorks, Inc.