How to extract the all combinations of array (permutations combinations)
4 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
the cyclist
2015 年 8 月 14 日
編集済み: the cyclist
2015 年 8 月 14 日
@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.)
採用された回答
the cyclist
2015 年 8 月 14 日
編集済み: the cyclist
2015 年 8 月 14 日
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 件のコメント
the cyclist
2015 年 8 月 21 日
編集済み: the cyclist
2015 年 8 月 21 日
The documentation for switch is pretty clear on how to handle this:
case {'Failure','Abort','Manual'}
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!