I update the HISTC method now that can work in ncolumn rows array:
% Data
n = 20; % number of rows
nd = 2; % number of colums of data
% Generate random matrix with values in (100:104)
A = 100+ceil(4*rand(n,nd))
% We want now to count the rows of A that are repeated
%% METHOD1: HISTC,
[u trash loc] = unique(A,'rows');
n = histc(loc,1:length(u));
fprintf('\nhist\n');
fprintf(['[ ' repmat('%f ',[1 nd]) '] occurs %d times\n'], [u n]');
%% METHOD2: ACCUMARRAY
% better than hist since accumarray has better complexity of O(m)
% It can also handle ND data
nd = size(A,2);
[u trash loc] = unique(A, 'rows');
n = accumarray(loc,1,[size(u,1) 1]);
fprintf('\nacccumarray\n');
fprintf(['[ ' repmat('%f ',[1 nd]) '] occurs %d times\n'], [u n]');
%% METHOD3: SORT
% A single SORT then just squeeze out the result by detecting jumps
nd = size(A,2);
[s is] = sortrows(A);
jump = diff(s,1,1);
jump(end+1,:) = Inf;
jump = find(any(jump,2)); % Use 'any' with find for ND data
u = s(jump,:);
n = diff([0; jump]);
fprintf('\nsort\n');
fprintf(['[ ' repmat('%f ',[1 nd]) '] occurs %d times\n'], [u n]');
% Bruno
