MATLAB: Starting with an array of x-y-z data, I need to find an array of unique values of x-y and as the z value the max z for the same (x,y) combination.

maximum

Hi,
I have x,y, z scatter data. I need to find for the same x and y coordinates the maximum z value. so for example:
x y z
1 2 10
2 2 5
2 1 8
2 2 7
I get:
x y z
1 2 10
2 1 8
2 2 7
Order of data is not important. Values in general are not integers.
Thanks for the help, I've tried differents methods with no success.

Best Answer

Try this
M = [
1 2 10
2 2 5
2 1 8
2 2 7];
[u_rows, ~, idx] = unique(M(:,[1 2]), 'rows');
max_vals = splitapply(@max, M(:,3), idx);
M_out = [u_rows, max_vals]
Result
>> M_out
M_out =
1 2 10
2 1 8
2 2 7