MATLAB: Repeated Values in matrix

MATLABmatrix array

Dear All;
I have an array of two columns, I want to find each repeated values of y for each x value and then the max of these y value to this x value and make new matrix in which for each x value there is a unique y value
how to do that ?

Best Answer

[uvals, ua, uc] = unique(xy(:,1));
maxy = accumarray(uc(:), xy(:,2), [], @max);
newarray = [uvals(:), maxy(:)];