Count the number of equal and different occurrences in an array
3 ビュー (過去 30 日間)
古いコメントを表示
PEDRO ALEXANDRE Fernandes
2022 年 4 月 1 日
コメント済み: Star Strider
2022 年 4 月 1 日
Good Morning.
In case I have an array with 200 or more rows. In this matrix, I have 3 columns but I need to count the number of equal and different occurrences.
Example:
column 1 column 2 column 3
1 0 0
2 0 0
3 1 1
4 0 1
5 1 1
6 1 0
...
and so on. What I want is to compare column 2 with column 3 and return the number of occurrences as I say below.
What I intend is:
1 1 -> appears 2 times (in the example)
0 1 -> appears 1 time and so on (in the example)
1 0 -> appears 1 time and so on (in the example)
0 0 -> appears 2 times and so on (in the example)
Only this replicated by 200 or more lines..
Any idea?
I think it's something easy but I can't think of anything
Thanks
0 件のコメント
採用された回答
Star Strider
2022 年 4 月 1 日
A = [1 0 0
2 0 0
3 1 1
4 0 1
5 1 1
6 1 0];
[Au23,ia,ix] = unique(A(:,[2 3]), 'rows');
Tally = accumarray(ix,1);
Result = [Au23, Tally]
.
2 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!