필터 지우기
필터 지우기

Count numbers of identical rows

조회 수: 36 (최근 30일)
Panayiotis Christodoulou
Panayiotis Christodoulou 2016년 5월 4일
댓글: Star Strider 2016년 5월 4일
Hi there,
I am a new member here.
I have a sample dataset:
3 5
3 5
5 6
5 6
5 6
5 7
6 8
I want the measure how many times does an identical row appears.
so the final result should be :
3 5 2
3 5 2
5 6 3
5 6 3
5 6 3
5 7 1
6 8 1
I have done it with a for loop but because my dataset is 8million x 2 if taking a lot of time and I am looking for an alternative solution.
Thanks
  댓글 수: 1
Star Strider
Star Strider 2016년 5월 4일
Panayiotis Christodoulou’s ‘Answer’ moved here:
there was an error on how the data were represented
please see atatched image

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2016년 5월 4일
This works:
M = [3 5
3 5
5 6
5 6
5 6
5 7
6 8];
[Mu,ia,ic] = unique(M, 'rows', 'stable'); % Unique Values By Row, Retaining Original Order
h = accumarray(ic, 1); % Count Occurrences
maph = h(ic); % Map Occurrences To ‘ic’ Values
Result = [M, maph]
Result =
3 5 2
3 5 2
5 6 3
5 6 3
5 6 3
5 7 1
6 8 1
  댓글 수: 2
Panayiotis Christodoulou
Panayiotis Christodoulou 2016년 5월 4일
thanks for your help!
100% working
Star Strider
Star Strider 2016년 5월 4일
My pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by