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

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2018년 9월 13일
편집: Andrei Bobrov 2018년 9월 13일

1 개 추천

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개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2018년 9월 13일

댓글:

2018년 9월 13일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by