# How to extract the all combinations of array (permutations combinations)

1 view (last 30 days)
Kanakaiah Jakkula on 13 Aug 2015
Edited: the cyclist on 21 Aug 2015
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
Kanakaiah Jakkula on 15 Aug 2015
Sir,
The meaning of resultant matrix I shown above is AA means A appeared after A. AB means B appeared after A like in row2. BA means A appeared after B. BC means C appeared after B as in row3 etc. I don't mind B appeared after A or after B itself). I just want to count how it appeared (that is after A or after B, or C) but how many time B appeared after A, and B appeared after B it self. Same as for A &C. That's why I want to count as below matrix:
Count_Matrix:
0 2 0
0 0 2
1 0 0
For instance, in the Count_Matrix(1,2) the count is 2, because B appeared after A twice at row2 &row5. Count_Matrix(3,1) the count is 1, because A appeared after C once at row4 etc.

the cyclist on 14 Aug 2015
Edited: the cyclist on 14 Aug 2015
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
the cyclist on 21 Aug 2015
Edited: the cyclist on 21 Aug 2015
The documentation for switch is pretty clear on how to handle this:
case {'Failure','Abort','Manual'}