Delete Negative Duplicates from Array

2 visualizaciones (últimos 30 días)
Sebastian
Sebastian el 25 de Mzo. de 2024
Comentada: Matt J el 25 de Mzo. de 2024
I have a 3-by-n array of points representing the vertices of a polyhedron. I need to identify all the axes that pass through the origin and a vertex, so I need to identify and remove all the points x where -x also exists in the array. I can manage this by iterating through every point and finding negatives, but it feels like there should exist a sneaky way to use the unique function to do the same thing but better.
Thanks in advance!

Respuesta aceptada

Matt J
Matt J el 25 de Mzo. de 2024
Editada: Matt J el 25 de Mzo. de 2024
X=randi(9,3,4); X=[X,-X(:,1:2)]
X = 3x6
5 8 7 6 -5 -8 4 8 9 3 -4 -8 2 5 4 1 -2 -5
map=triu(squeeze(~any(X+reshape(X,3,1,[]),1)));
[I,J]=find(map);
X(:,[I;J])=[]
X = 3x2
7 6 9 3 4 1
  2 comentarios
Sebastian
Sebastian el 25 de Mzo. de 2024
That's pretty impressive, but unfortunately I want to only get rid of 1 of the pair of opposite vectors, not both. For instance, in your example, I'd want it to only remove the last two columns (or just the first two). Sorry if that wasn't clear.
Matt J
Matt J el 25 de Mzo. de 2024

Iniciar sesión para comentar.

Más respuestas (1)

Catalytic
Catalytic el 25 de Mzo. de 2024
X=rand(3,4); X=[X,-X(:,1)]
X = 3x5
0.2765 0.5016 0.7075 0.8914 -0.2765 0.8997 0.8842 0.9797 0.0281 -0.8997 0.7290 0.1868 0.9017 0.4237 -0.7290
[~,~,G]=unique([X,-X]','rows');;
[N,~,bin]=histcounts(G,1:max(G)+1);
bin=bin(1:end/2);
X(:,N(bin)>1)=[]
X = 3x3
0.5016 0.7075 0.8914 0.8842 0.9797 0.0281 0.1868 0.9017 0.4237

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by