function [nextState]=MarkovProcess(currentState,P)
% given current state of the system and transition probability matrix will
% output the next state of the system. If the current state of the system
% is not observed (sum across the row is zero) then will choose at random
% from a distribution of possible states.
% state 1-->n (dont start at zero)
C=cumsum(P(currentState,:));
r=rand;
nextState=find(r<=C,1);
if isempty(nextState)
possibleStates=find(sum(P,2));
nextState=randsample(possibleStates,1);
else
end
end