Extract the maximum weight from each subset of overlapping points
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Maurilio Matracia
le 23 Jan 2021
Modifié(e) : Nolan Canegallo
le 24 Jan 2021
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 commentaires
Réponse acceptée
Nolan Canegallo
le 24 Jan 2021
Modifié(e) : Nolan Canegallo
le 24 Jan 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
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Triangulation Representation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!