フィルターのクリア

Find unique rows (including rows with reverse x,y) in matrix of x,y coordinates

3 ビュー (過去 30 日間)
Hi, I would appreciate your comments on this problem.
I would like to extract unique coordinates for example if x=1, y=2, then this point is similar to y=2,x=1 and only one pair is kept.
x y
1 2
2 1
2 3
3 2
I have tried two approaches; A) using unique comments
[uniqueA M2 M3] = unique(data(:,[1:2]),'rows'); This found no unique row
b) a for loop which I couldn't complete
for j=1:358
clear row3
[row1,col1,v1]=find(data(j,1));
[row2,col2,v2]=find(data(j,2));
[row3,col3,v3]=find(data(:,2)==v1 & Tab_Vn_values2(:,1)==v2);
Tab_Vn_valuesTest(j,:)=Tab_Vn_values2(row3,:);
end
Thank you for your time
  3 件のコメント
Peyman Obeidy
Peyman Obeidy 2018 年 9 月 25 日
I think it is only looking at x1=x2 and y1=y2. Is this right?
Peyman Obeidy
Peyman Obeidy 2018 年 9 月 25 日
Thank you KSSV for always being helpful too.

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

採用された回答

Bruno Luong
Bruno Luong 2018 年 9 月 25 日
編集済み: Bruno Luong 2018 年 9 月 25 日
Try
[~,i] = unique(sort(data(:,1:2),2),'rows')
data(i,:)
  3 件のコメント
Bruno Luong
Bruno Luong 2018 年 9 月 25 日
編集済み: Bruno Luong 2018 年 9 月 25 日
nothing mysterious
if you want pair (x1,y1) matches the pair (x2,y2) regardless if you swap x and y (in other word after applying any permutation of 2 elements), meaning that if and only if you sort them they matches in order. Sorting a permuted array will bring them back to a unique state.
Peyman Obeidy
Peyman Obeidy 2018 年 9 月 25 日
Thank you, great

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by