Reputation: 23
I'm trying to model random walk mobility model in matlab I'm facing problem regarding finding the next state from a transition matrix. I have already created my state transition matrix but I dont know how to find the next state ?
I know I have all the probabilities for each state from the trasition matrix but I need to actually choose based on those probability what the next state will be. can someone help me with that ?
Upvotes: 1
Views: 1824
Reputation: 2263
Or if you want to use a built-in toolbox function:
n=100; %number of moves
emis=ones(1,length(A)) % it's not a Hidden Markov Model so this can be just ones. ignore.
[~,moves] = hmmgenerate(n, A, emis); % starts at state 1 don't forget
Upvotes: 0
Reputation: 156
If A
is your transition matrix with rows summing to 1, then you can simulate the Markov chain like this:
cdf = cumsum(A,2);
for t =1:numSteps
stateIndex = min(find(rand < cdf(stateIndex,:)));
% ....
end
Upvotes: 1