フィルターのクリア

Remove rows/columns with same elements

23 ビュー (過去 30 日間)
Asad Gulib
Asad Gulib 2020 年 11 月 17 日
コメント済み: Asad Gulib 2020 年 11 月 17 日
Hi,
Is there a easy way to remove rows with same elements in a 2D matrix. For example, i have a matrix A = [1 2; 2 3; 1 2; 3 4; 2 1]
The 'unique' command doesn't help as it will give you the output [1 2; 2 3; 3 4; 2 1]. It's not deleting the last row [2 1] which has the same element as first row.
But i want the output like this [1 2; 2 3; 3 4].
Thanks,
Asad

採用された回答

Andrei Bobrov
Andrei Bobrov 2020 年 11 月 17 日
[~,i] = unique(sort(A,2),'first','rows');
out = A(i,:);
  1 件のコメント
Asad Gulib
Asad Gulib 2020 年 11 月 17 日
Thanks!!!

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

その他の回答 (1 件)

Timo Dietz
Timo Dietz 2020 年 11 月 17 日
unique(sort(A, 2), 'rows')
  1 件のコメント
Asad Gulib
Asad Gulib 2020 年 11 月 17 日
Thanks!!!

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

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by