Using matlab to calculte the transition matrix