Extract the maximum weight from each subset of overlapping points
2 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
I have a set of coordinates with some overlapping points (lat, lon).
Here's an easy example:
lat = [ 0 0 0 1 2 2 2 ] ;
lon = [ 0 1 0 4 5 6 5 ] ;
weight = [ 1 2 3 4 5 6 7 ] ;
Coord = [0 0; 2 5] ;
MaxWeight = [3, 7] ;
so evidently the first and the third points, as well as the fifth and the seventh, have the same coordinates Coord(1,:) and Coord(2,:).
I would like to write a code so that I can determining the MaxWeight vector by finding all the subsets with overlapping points and extract the maximum weight from each subset.
Thanks in advance
0 个评论
采纳的回答
Nolan Canegallo
2021-1-24
编辑:Nolan Canegallo
2021-1-24
Probably not the most efficient way, but this seems to solve your problem.
clear; clc;
lat = [ 0 0 0 1 2 2 2 ] ;
lon = [ 0 1 0 4 5 6 5 ] ;
weight = [ 1 2 3 4 5 6 7 ] ;
overlap = any(and(lat(:)==lat, lon(:)==lon)-eye(length(weight)));
Coord = unique([lat(overlap);lon(overlap)]','first','rows');
for i = size(Coord,1):-1:1
MaxWeight(i) = max(weight(lat==Coord(i,1)&lon==Coord(i,2)));
end
Results:
Coord =
0 0
2 5
MaxWeight =
3 7
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Triangulation Representation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!