How to delete all repeat rows?

1 Ansicht (letzte 30 Tage)
Wang Jack
Wang Jack am 19 Mai 2020
Kommentiert: Rik am 22 Mai 2020
How to delete all repeat rows?
I mean all repeat rows, like :
A=
[0 4;
2 4;
0 4;
4 8;
3 4]
How to got new_A=
[2 4;
4 8;
3 4]

Akzeptierte Antwort

Rik
Rik am 19 Mai 2020
Bearbeitet: Rik am 19 Mai 2020
There is probably a more efficient way, but you can use unique() to get all first occurrences. Then you can use the second output to find all removed rows, which you can use as an input to setdiff.
A=[0 4;2 4;0 4;4 8;3 4;0 4];
[B,ind]=unique(A,'stable','rows');
ind=setdiff(1:size(A,1),ind);
B=setdiff(B,A(ind,:),'rows');
  4 Kommentare
Wang Jack
Wang Jack am 22 Mai 2020
Aaaaaawesome, thanks for the help!
Rik
Rik am 22 Mai 2020
Glad to be of help. If it solved your problem, please consider marking it as accepted answer. If not, feel free to comment with your remaining issues.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by