Extract the maximum weight from each subset of overlapping points

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Nolan Canegallo
Nolan Canegallo il 24 Gen 2021
Modificato: Nolan Canegallo il 24 Gen 2021
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

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by