Delete Array Element Based on Conditions
Ältere Kommentare anzeigen
Hello,
I have an array Coordinates 3133x3 that contains the 3 coordinates (x,y,z) of a list of points. Column 1 is the x, column 2 the y and column 3 the z.
Inside this array I would like to remove some points (rows) besed on 2 different conditions:
1) Delete all points (so delete the corresponding rows in Coordinates) with z-coordinates that is more than +-5 aways from this reference z_ref array.
So for example if a point has z-coordinate 400 it will be deleted, contrary if it has z-ccordinate 410 or 412 it will be keeped. This to remove the outliers present.
z_ref = [411.2966 426.2966 441.2966 456.2966 471.2966 486.2966 501.2966 545 575 605 635 665 695];
2) If there are more points with the same z-coordinate (again in a range of +-5) keep just the one with the z-coordinate closer to z_ref. This the remove coinciding points and keeping just one.
for i = 1:length(Coordinates)
for j = z_ref
if Coordinates(i,3) >= j + 5 || Coordinates(i,3) <= j - 5
Coordinates(i,:) = [];
elseif Coordinates(i,3) <= Coordinates(i+1,3) + 5 || Coordinates(i,3) >= Coordinates(i+1,3) - 5
Coordinates(i+1,:) = [];
end
end
end
This is what I tried but it doesn't work.. Otherwise I was checking other methods like mask but still I was not able to make it works
Please help me, thanks in advance
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Multidimensional Arrays finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!