Frequency of unique rows
3 次查看(过去 30 天)
显示 更早的评论
I want to count the frequency of the similar rows in a very long matrix. I have one million rows. I want something like below,
I have a matrix like below,
[0 0 0 0
0 0 0 0
0 0 0 1
0 0 0 1
0 0 0 1
0 0 0 2
0 0 0 2]
And I am looking for an output like below,
[0 0 0 0 2
0 0 0 1 3
0 0 0 2 2]
Thanks
0 个评论
采纳的回答
Andrei Bobrov
2018-9-13
编辑:Andrei Bobrov
2018-9-13
a = [0 0 0 0
0 0 0 0
0 0 0 1
0 0 0 1
0 0 0 1
0 0 0 2
0 0 0 2];
[aa,~,c] = unique(a,'rows');
out = [aa, histcounts(c,1:max(c)+1)'];
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!