Use accumarray with min to find the minimum values ββfor each group:
v = accumarray( a(:,2), a(:,1), [], @min )
To get the minimum indices, build the lines:
idx = find(ismember(a, [v, unique(a(:, 2))], 'rows'))
Also, if you have m predefined groups, you can use (1:m)' instead of unique(...) .
Shai source share