n = 1e1;                % The number of slots to be considered
S = [1,2];              % Two possible states
P = [2/5 3/5; 1/2 1/2]; % Transition probability matrix
X1 = 2;                 % Initial state

X = MarkovChainGS(n,S,P,X1)

% Approximate the transition probabilities from the simulation
P_sim = []; x = X(1:(n-1)); y = X(2:n);
for k = 1:length(S)
    I = find(x==S(k)); LI = length(I);
    yc = y(I); cond_rel_freq = hist(yc,S)/LI; 
    P_sim = [P_sim; cond_rel_freq];
end
P_sim                   

% Approximate the proportions of time that the states occur
p_sim = hist(X,S)./n
