MATLAB: Find repeated vectors in matrix

MATLABrepeated vectors matrix

Hello everyone
i want to detect all repeated vectors in matrix and counting them for example
A=[1 0 0 1 0 0 ; 1 1 0 0 0 1; 1 0 0 1 0 0 ; 1 0 1 0 1 0 ; 1 0 0 1 0 0;1 1 0 0 1] here there is two vectors repeated a1= 1 0 0 1 0 0 repeated 3 times and a2=[1 1 0 0 1] repeated twice
any help please ^^

Best Answer

There’s a ‘0’ missing in the last row of ‘A’. With that corrected:
A = [1 0 0 1 0 0 ; 1 1 0 0 0 1; 1 0 0 1 0 0 ; 1 0 1 0 1 0 ; 1 0 0 1 0 0; 1 1 0 0 0 1];
[Au,ia,ic] = unique(A, 'rows', 'stable');
Counts = accumarray(ic, 1);
Out = [Counts Au]
Out =
3 1 0 0 1 0 0
2 1 1 0 0 0 1
1 1 0 1 0 1 0
The number of occurrences are in the first column and the vectors themselves in the following columns.