Extract the maximum weight from each subset of overlapping points

2 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Nolan Canegallo
Nolan Canegallo el 24 de En. de 2021
Editada: Nolan Canegallo el 24 de En. de 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

Más respuestas (0)

Categorías

Más información sobre Triangulation Representation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by