You have to create a matrix which counts transitions.
For the row 1,4,4,6,7
You have to set
M(1,4)=M(1,4)+1
M(4,4)=M(4,4)+1
M(4,6)=M(4,6)+1
M(6,7)=M(4,7)+1
Finally normalize every row to sum 1.
Update: Using char indices. Matlab can transform every char to a number using double('A')
, thus it is simple index shifting.
char2index=@(x)(double(x)-'A'+1)
index2char=@(x)(char(x+'A'-1))
M(char2index('A'),char2index('B'))=M(char2index('A'),char2index('B'))+1
The second function index2char
transforms indices back to the character.