필터 지우기
필터 지우기

How do I know the frequency of each unique pair?

조회 수: 2 (최근 30일)
Shounak Shastri
Shounak Shastri 2014년 3월 30일
답변: Jos (10584) 2014년 3월 30일
Edited by Azzi after Shounak changed his question
I have a uint8 matrix nx2, I want to know the frequency of each unique pair
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2014년 3월 30일
Why did you change your question?
Shounak Shastri
Shounak Shastri 2014년 3월 30일
I thought i was not clear, so I explained the problem

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

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 3월 30일
A=uint8([1 2;3 4;1 2;5 6;1 2;5 6])
[ii,jj,kk]=unique(A,'rows')
f=histc(kk,1:numel(jj)) %frequencies
out=[ii f] ; % the first two columns represent ii, the third represent the frequency

Jos (10584)
Jos (10584) 2014년 3월 30일
Here's a one-liner that works if the input is of a N-by-2 matrix with positive integers:
A=uint8([1 2; 3 4;1 2;5 6;1 2;5 6 ; 255 254 ; 255 254])
[B(:,1) B(:,2) B(:,3)] = find(accumarray(A,1)) ;
disp(B) % column 1-2, unique rows of A, column 3 is frequency of occurrence

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by