MATLAB: How to extract the all combinations of array (permutations combinations)

statisticssystem

Hi,
I have a matrix as below:
A Success
B Failure
C Success
A Success
B Success
C Success
I want to count how many time B appeared after A or A appeared after A or C appeared after B (for example: i-1 should be A, and i should B: so it counted as AB). The resultant combinations are as shown below: So, again I want to count how many time A appeared after A, B appeared after A, B appeared after B, C appeared after B (or C,or A,or D)etc.
AA AB AC
BA BB BC
CA CB CC
My out put should be: Out_sucess (only succeefull combinations):
0 1 0
0 0 2
1 0 0
Out_Fail(Failed combinations):
0 1 0
0 0 0
0 0 0
Kindly help how do I get these out puts

Best Answer

Perhaps not the most efficient way, but here is a very pedantic way:
M = {
'A' 'Success'
'B' 'Failure'
'C' 'Success'
'A' 'Success'
'B' 'Success'
'C' 'Success'};
[~,loc] = ismember([M(1:end-1,1) M(2:end,1)],{'A','B','C'});
[successCount,failureCount] = deal(zeros(3));
for ni = 1:size(loc,1);
switch M{ni+1,2}
case 'Success'
successCount(loc(ni,1),loc(ni,2)) = successCount(loc(ni,1),loc(ni,2)) + 1;
case 'Failure'
failureCount(loc(ni,1),loc(ni,2)) = failureCount(loc(ni,1),loc(ni,2)) + 1;
end
end
successCount
failureCount