MATLAB: How to remove duplicates in matrix with condition

conditionmatrixremove duplicate

Hi everyone,
I just want to remove duplicates from NX2 matrices according to greatest value from column 2. for instance lets say we have 5×2 matrices;
X = [1 10;2 20;3 30;3 31;3 32]
at the result ı want to find
Xresult = [1 10;2 20;3 32]
So, I want to eliminate duplicates in "3" values and I want to see greatest "3" value in order to interpret my work.
Regards,

Best Answer

X = [1 10;2 20;3 30;3 31;3 32];
Xs=sortrows(X);
[~,I]=unique(Xs(:,1),'last');
XResult = Xs(I,:)