0

I have got a question. I have a matrix with three columns (X,Y,Z coordinates) and nearly 60000 rows. Now, I would like to compare the X and Z values of all 60000 rows. All rows whose X and Z values only occur once should be deleted, only the rows whose X and Z value occur twice or more should be regarded. Next, the rows with the equal X and Z values should be compared and the row with the highest Y value should be written into a new matrix. I thought about using a loop (which is attached) for the search of the rows with equal X and Z values but I think that the computing time is quite high, is there a better way? And how do I define the "do"?

I haven't thought about the the search of the higher Y value, yet.

for k = 1:end
for m = k+1:end
   if A(k,1) == A(m,1) && A(k,3) == A(m,3)
     % do something
   end
end
end
Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
  • 1
    [`unique`](https://mathworks.com/help/matlab/ref/unique.html) can do this. Simply check whether a unique X/Z pair occurs only once and then delete it from the array. – Adriaan Oct 07 '19 at 10:26
  • Thanks for your answer but how can I use the unique comment to delete the unique rows? I only know how to write them in a new matrix (for example: B = unique(A(:,[1 3]),'rows')). Maybe I have some kind of a brainlag. –  Oct 07 '19 at 10:49
  • 2
    Are the values integer or arbitrary real numbers? If they are real, you may want to compare with a tolerance to avoid [floating-point precision issues](https://stackoverflow.com/questions/686439/why-is-24-0000-not-equal-to-24-0000-in-matlab) – Luis Mendo Oct 07 '19 at 10:53
  • They are points of the surface of a stl model. –  Oct 07 '19 at 10:55

0 Answers0