MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Radhika Malik
on 30 May 2013

I'm trying to build the transition matrix for a Markov Chain in MATLAB; I have several different observation sequences (all of varying lengths) and I need to generate the transition matrix using those.

To build a transition matrix with a single observation sequence, I can use--

x = [1 6 1 6 4 4 4 3 1 2 2 3 4 5 4 5 2 6 2 6 2 6]; % the Markov chain tm = full(sparse(x(1:end-1),x(2:end),1)) % the transition matrix.

How can I construct one using state sequences of different length? One example can be that one sequence is 1,2,3,4 and another is 4,5,6.

*No products are associated with this question.*

## 1 Comment

## Tom Lane

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/77537#comment_152346

Can you explain more about what you want? If the two sequences are using different sets of states, how to you want to define a transition matrix? Is the issue that there may not be enough data so that all states appear in both sequences, even though they were theoretically possible? Or do you just want a separate transition matrix for each sequence? Or are the states such that you can't escape from certain subsets of states once you get into them? Or ...?