Remove all rows of an array based on a value in a column, and also remove all rows that have the same values as this row in other columns

Hi, I have the centroids (x,y) of e.g 3 objects as shown in the pic:
I also have an array of the centroid locations (x,y) of each point and then calculate the distance of every other point from that point. Columns 1, 2 are (x,y) of an object, 3rd and 4th columns are coordinates of other objects, and column 5 is their seperation
M =
15.88 18.43 15.88 18.43 0
15.88 18.43 33.48 14.99 17.94
15.88 18.43 53.49 37.71 42.27
33.48 14.99 15.88 18.43 17.94
33.48 14.99 33.48 14.99 0
33.48 14.99 53.49 37.71 30.27
53.49 37.71 15.88 18.43 42.27
53.49 37.71 33.48 14.99 30.27
53.49 37.71 53.49 37.71 0
what I want to do is e.g. select a distance i.e. d=40, and then remove all rows in which column 5 (= their seperation) is above this value AND also any other row that has the same values in col 1 & 2. i.e. so to completely remove any object that is close to another object.
This is my attempt:
% Create another matrix where the condition is met
M1=M(M(:,5) < d, :);
disp('after')
M1
% Create conditions
TF1 = M(:,1)==M1(:,1)
TF1 = M(:,2)==M1(:,2)
% combine them
TFall = TF1 & TF2
% remove
M(TFall,:) = []

4 comentarios

Almost, but that only removed the exact row where dr was less than the required value. But it still left in objects if they were further tmaway from another object. So what i want is to exclude any object if its near any other object
Wasn't your question the same in that post, however? If so, you should not start a a new post with the same quesiton. You should provide feedback to those answers, indicating in what way they do or do not fulfill the question.
Matt, it was towards the same goal yes, but I realised that finding the distance of all objects and simply finding rows where this is below a set value doesn't quite work - but it did answer the main question - how to find distance of all objects!. Yes I could have added this problem in a comment there too, but this is more of a general matrix manipulation problem (i.e. use column 5 to flag the values in columns 1 & 2 and then put remove all rows that have these col 1& 2 values. I thought as its a different Matlab problem it would be easier to search for as well so I created a new thread.

Iniciar sesión para comentar.

 Respuesta aceptada

M = [
15.88 18.43 15.88 18.43 0
15.88 18.43 33.48 14.99 17.94
15.88 18.43 53.49 37.71 42.27
33.48 14.99 15.88 18.43 17.94
33.48 14.99 33.48 14.99 0
33.48 14.99 53.49 37.71 30.27
53.49 37.71 15.88 18.43 42.27
53.49 37.71 33.48 14.99 30.27
53.49 37.71 53.49 37.71 0 ];
xy=M(:,1:2)
xy = 9×2
15.8800 18.4300 15.8800 18.4300 15.8800 18.4300 33.4800 14.9900 33.4800 14.9900 33.4800 14.9900 53.4900 37.7100 53.4900 37.7100 53.4900 37.7100
M(ismember(xy,xy(M(:,5)>40,1:2),'rows'),:)=[]
M = 3×5
33.4800 14.9900 15.8800 18.4300 17.9400 33.4800 14.9900 33.4800 14.9900 0 33.4800 14.9900 53.4900 37.7100 30.2700

1 comentario

Thankyou, I modified it slightly to remove the rows with the last coloumn as zero and it worked beautifully
TF1 = M(:,5)==0;
M(TF1,:) = []

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Versión

R2022a

Etiquetas

Preguntada:

el 9 de Ag. de 2022

Comentada:

el 9 de Ag. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by