MATLAB: Extract the Maximum Column elements of every Row

matrix manipulation

Hello , I have an array
A = [8 4; 3 6; 2 7; 1 4; 2 3;2 1;3 1; 3 5; 8 6; 8 1];
I want to extract maximum column elements for every Row.
In the above array A i have
3 1 ; 3 5 ; 3 6
I want only 3 6 to be retained as that is the maximum column for that row.
Similarly i have 8 1 ;8 4; 8 6 I want only 8 6 as that has the maximum column value.
Final output I want for the array A is as follows
ans =
1 4;
2 7;
3 6;
8 6;
Looking forward to hear from you at the earliest
Thanks
Pankaja

Best Answer

Your wording is rather poor. It looks like what you want to do is for each unique value in the first column find the corresponding maximum in the second column. This is trivial to obtain with unique and accumarray:
A = [8 4; 3 6; 2 7; 1 4; 2 3;2 1;3 1; 3 5; 8 6; 8 1];
[val, ~, subs] = unique(A(:, 1));
B = [val, accumarray(subs, A(:, 2), [], @max)]