Filter löschen
Filter löschen

How do I know the frequency of each unique pair?

2 Ansichten (letzte 30 Tage)
Shounak Shastri
Shounak Shastri am 30 Mär. 2014
Beantwortet: Jos (10584) am 30 Mär. 2014
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 Kommentare
Azzi Abdelmalek
Azzi Abdelmalek am 30 Mär. 2014
Why did you change your question?
Shounak Shastri
Shounak Shastri am 30 Mär. 2014
I thought i was not clear, so I explained the problem

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Azzi Abdelmalek
Azzi Abdelmalek am 30 Mär. 2014
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) am 30 Mär. 2014
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

Community Treasure Hunt

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

Start Hunting!

Translated by