i've a matrix of 6x4 and i want to count the rows how many times it occur in a matrix
1 回表示 (過去 30 日間)
古いコメントを表示
let say the matrix is
A=[ 12 45 67 89
34 56 78 65
12 45 67 89
53 55 21 90
12 45 67 89
53 55 21 90 ]
i want the output to be as:
12 45 67 89 ----- 3 % because it occurs 3 times
34 56 78 65 ------1
53 55 21 90 ------2
plz help me
0 件のコメント
採用された回答
Azzi Abdelmalek
2013 年 5 月 8 日
A=[ 12 45 67 89
34 56 78 65
12 45 67 89
53 55 21 90
12 45 67 89
53 55 21 90 ]
[a,b,c]=unique(A,'rows','stable');
v=arrayfun(@(x) sum(c==x),1:size(a,1))';
out=[a v]
2 件のコメント
Emma Cairns
2017 年 8 月 9 日
I have an instance where I need to do this twice with two separate matrices and I keep getting the same output for both using this code, is there any way I can make it work? Thanks!
その他の回答 (1 件)
Andrei Bobrov
2013 年 5 月 8 日
A=[ 12 45 67 89
34 56 78 65
12 45 67 89
53 55 21 90
12 45 67 89
53 55 21 90 ];
[a,c,c] = unique(A,'rows');
out = [a, histc(c,1:max(c))];
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!