If you don't mind doing some preprocessing to get the order (or if the first column is well built from 1 to n
), you can do it like this:
accumarray([1 2 3 1]',[11 12 13 14]',[],@max)
This will give:
14 12 13
Or in your case:
accumarray(M(:,1),M(:,2),[],@max)
Pay attention to the order. For example, the second number will correspond to M(:,1) == 2
Dennis jaheruddin
source share