フィルターのクリア

Delete row with same value but in different columns

3 ビュー (過去 30 日間)
Danilo Sanfilippo
Danilo Sanfilippo 2019 年 7 月 24 日
回答済み: Jeroen Houwen 2021 年 6 月 24 日
I would like to eliminate rows in the matrix with the same value but in different columns
i want the couples are unique in all rows and in all columns
i used "unique" but it delete rows with same value in same columns
...
2 9 % this value is repeat
2 77
2 157
2 399
2 909
2 1247
3 76
3 175
3 398
3 1164
3 1294
4 82
4 169
...
9 2 % this value is repeat
9 10
9 257
...
i used this code but it is not work
for i = 1:length(A)
for j = i+1:length(A)
if ((A(i,1) ~= A(j,2)) && (A(i,2) ~= A(j,1)))
B(n,1) = n
B(n,2) = A(i,1)
B(n,3) = A(i,2)
n = n+1
end
end
end
  4 件のコメント
Danilo Sanfilippo
Danilo Sanfilippo 2019 年 8 月 2 日
no sorry
madhan ravi
madhan ravi 2019 年 8 月 2 日
isequal(Wanted,D)

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

回答 (2 件)

madhan ravi
madhan ravi 2019 年 7 月 24 日
編集済み: madhan ravi 2019 年 7 月 24 日
Wanted = unique(sort(matrix,2),'rows')
%or perhaps you want:
[~,idx] = unique(sort(matrix,2),'rows');
Wanted = matrix(idx,:)
  2 件のコメント
Danilo Sanfilippo
Danilo Sanfilippo 2019 年 7 月 24 日
Unfortunately it is not what i asked for, but many thanks.
basically i want to delete just one of this row.
According with the previuos example
when i have [2 9; ...; 9 2 ] i want to delete just one of this row.
P.s. the previous code delete other row that were not double
many thanks
madhan ravi
madhan ravi 2019 年 7 月 24 日
Instead of describing, why not show the desired output???

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


Jeroen Houwen
Jeroen Houwen 2021 年 6 月 24 日
Dear Danilo,
I might have a simpler version that also works. It is probably a bit late but it is something!
stp = 0;
while stp < length(A)
stp = stp + 1;
A(A(:,1) == A(stp,2),:) = [];
end

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by