MATLAB: Find in a matrix value pair.

for loopmatrixmatrix manipulationread data

I have a matrix with 8 column and 250 raw. I need to create a function that read the first two column and and analyze the combination of this two value. For Example the matrix is
A|B|…
A|C|…
C|A|…
A|C|…
C|A|…
and I would like to have as output the single value pairs and the repetitions number . For example : A|B|1
A|C|2
C|A|2…
Could you help me please?

Best Answer

k = { 'bc' 'ec'
'ed' 'cd'
'dc' 'ec'
'bc' 'be'
'ed' 'cd'
'ed' 'ae'
'bc' 'ec'
'ba' 'bb'
'ca' 'aa'
'ab' 'ad'}
[a,c,c] = unique(k);
B = reshape(c,size(k));
[N,M,M] = unique(B,'rows');
p = histc(M,1:max(M));
out = [a(N),num2cell(p)];