finding the next states from transition matrix ? random walk Matlab simulation

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 ?

Answers


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

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 

Need Your Help

XCode and developer tools

iphone macos

I want to use the FileMerge utility on my mac, but it isn't installed. I searched in Google and there is written that it will be installed with the developer tools. Where can I find the developer t...

Run a ejb outside it's container in Netbeans

netbeans ejb ejb-3.0 netbeans-6.9

I am using netbeans to run my web application. Now, in my web application project, I have a jsp code which call a servlet and that servlet call's a EJB and shows the output of EJB in a jsp page. No...