How to extract the all combinations of array (permutations combinations)
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kanakaiah Jakkula
am 13 Aug. 2015
Bearbeitet: the cyclist
am 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
4 Kommentare
the cyclist
am 14 Aug. 2015
Bearbeitet: the cyclist
am 14 Aug. 2015
@dpb, I think he/she is only looking at "nearest neighbor" pairs, and basing the classification on the success/failure of the 2nd member of the pair. (At least, this gives the quoted result.)
Akzeptierte Antwort
the cyclist
am 14 Aug. 2015
Bearbeitet: the cyclist
am 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
11 Kommentare
the cyclist
am 21 Aug. 2015
Bearbeitet: the cyclist
am 21 Aug. 2015
The documentation for switch is pretty clear on how to handle this:
case {'Failure','Abort','Manual'}
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!