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!