フィルターのクリア

Delete Negative Duplicates from Array

2 ビュー (過去 30 日間)
Sebastian
Sebastian 2024 年 3 月 25 日
コメント済み: Matt J 2024 年 3 月 25 日
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!

採用された回答

Matt J
Matt J 2024 年 3 月 25 日
編集済み: Matt J 2024 年 3 月 25 日
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 件のコメント
Sebastian
Sebastian 2024 年 3 月 25 日
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 2024 年 3 月 25 日

サインインしてコメントする。

その他の回答 (1 件)

Catalytic
Catalytic 2024 年 3 月 25 日
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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by