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.
2 views (last 30 days)
Show older comments
Fabrizio Argentieri
on 8 Nov 2020
Commented: Fabrizio Argentieri
on 9 Nov 2020
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.
0 Comments
Accepted Answer
Ameer Hamza
on 8 Nov 2020
Edited: Ameer Hamza
on 8 Nov 2020
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
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!