%% Create Markov Chain Using Matrix of Transition Probabilities
% Consider this theoretical, right-stochastic transition matrix of a stochastic process.
% P = \left[ {\begin{array}{*{20}{c}}
% {0.5}&{0.5}&0&0\\
% {0.5}&0&{0.5}&0\\
% 0&0&0&1\\
% 0&0&1&0
% \end{array}} \right].
% Element P_{ij} is the probability that the process transitions to state j at time t + 1 given that it is in state i at time t, for all t.
% Create the Markov chain that is characterized by the transition matrix P.

P = [0.5 0.5 0 0; 0.5 0 0.5 0; 0 0 0 1; 0 0 1 0];
mc = dtmc(P);

% mc is a dtmc object that represents the Markov chain.
%
% Display the number of states in the Markov chain.

numstates = mc.NumStates

%
% Plot a directed graph of the Markov chain.

figure;
graphplot(mc);

% Observe that states 3 and 4 form an absorbing class, while states 1 and 2 are transient.
% Copyright 2012 The MathWorks, Inc.