MATLAB: Finding unique rows with largest value in 3rd column

matrix

Suppose I have a matrix
A=
1 2 3
1 3 8
2 1 3
2 1 5
2 2 8
1 2 9
4 3 2
I want to find a matrix which has unique first column and largest 3rd column.. So my resultant matrix should be
1 2 9
2 2 8
4 3 2
Any help will be highly appreciated!

Best Answer

Assuming that the order of the first two columns doesn't matter and that your expected matrix is missing [1 3 8]
Old/clarified in comments
x = [1 2 3
1 3 8
2 1 3
2 1 5
2 2 8
1 2 9
4 3 2];
[uv,~,idx] = unique(sort(x(:,[1 2]),2),'rows');
v = accumarray(idx,x(:,3),[],@max);
vv = [uv v]
vv =
1 2 9
1 3 8
2 2 8
3 4 2