Improve performance on finding max values of matrix
Afficher commentaires plus anciens
Hi everyone,
I have a performance issue with finding the maximum values of a matrix:
I have a matrix of 3D coordinates of points in the form
data=[X1 Y1 Z1, X2 Y2 Z2, ..., Xn Yn Zn]
With n over about 4.10^6
The values of X and Y are a grid, so basically I have about 3000 times the same Y values (Y1 to Y3000 are equal, Y3001-Y6000 are equal…). I want to find for each Y coordinate the maximum X coordinate. What I currently have is:
while i<length(data) %find for each Y Xmax
xmax(j)=max(data(data(:,2)==data(i,2),1));
ymax(j)= data(i,2);
i=find(data(:,2)== data(i+1,2), 1, 'last');
j=j+1;
end
This takes about 3 min to execute. Is there a better way to do this?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Choose a Solver dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!