Sorting a vector with another vector of multiple maximums
Afficher commentaires plus anciens
Hi,
I have a function that I want to compute a queue "Qevents", which gets information from a set of points "P" (columns x and y) and sorts them by maximum y value. If there are other (same) maximum y values, I want to store the maximum y-value that has the largest corresponding x value. As the code is executed, points are deleted from the original data set so a new maximum can be examined. I have started writing out the code to this:
% given a list of points P(n,2) representing x,y coordinates
for i=1:length(P)
indx = P==max(P(:,2)); % find index of maximum in set of points..
if "multiple maximums" % don't know the code for this line
if indx(i,1)==1 && indx(i,2)==1 % checks for maximums in both columns
Qevents(i) = max(P(:,2)); % stores maximum y-value recursively
P(i,:) = []; % and removes it from the list of points
end
else
Qevents(i) = max(P(:,2))
P(indx) = [];
end
end
I have no idea how to check for multiple maximums and use it in a loop properly. Any help would be appreciated. Thanks!
Ian
Réponse acceptée
Plus de réponses (1)
Catégories
En savoir plus sur Shifting and Sorting Matrices dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!