Filter löschen
Filter löschen

Delete Negative Duplicates from Array

2 Ansichten (letzte 30 Tage)
Sebastian
Sebastian am 25 Mär. 2024
Kommentiert: Matt J am 25 Mär. 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!

Akzeptierte Antwort

Matt J
Matt J am 25 Mär. 2024
Bearbeitet: Matt J am 25 Mär. 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 Kommentare
Sebastian
Sebastian am 25 Mär. 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 am 25 Mär. 2024

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Catalytic
Catalytic am 25 Mär. 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

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by