How can I create unique rows in a matrix?

2 Ansichten (letzte 30 Tage)
AK Nahin
AK Nahin am 27 Okt. 2020
Bearbeitet: Sudhakar Shinde am 27 Okt. 2020
I write a program and the output is like:
C =
0 0 0
3 6 6
4 5 6
4 6 5
5 4 6
5 5 5
5 6 4
6 3 6
6 4 5
6 5 4
6 6 3
Now I want to short rows and then delete unique rows. like there will be anly 4 5 6 not both 4 5 6 and 4 6 5. I think you get it. Thank you
  1 Kommentar
Sudhakar Shinde
Sudhakar Shinde am 27 Okt. 2020
Bearbeitet: Sudhakar Shinde am 27 Okt. 2020
Row with value- 4 5 6 and 4 6 5 are not duplicated these are two separate unique rows.
Example: A=[1 2 3; 3 4 5;1 2 3]; here 1st and 3rd row is duplicated. Now you can use 'unique' function to remove duplicate row.
[C,ia,ic] = unique(A,'rows');
uA = A(ia,:); %unigue array

Melden Sie sich an, um zu kommentieren.

Antworten (1)

KSSV
KSSV am 27 Okt. 2020
Bearbeitet: KSSV am 27 Okt. 2020
A = [ 0 0 0
3 6 6
4 5 6
4 6 5
5 4 6
5 5 5
5 6 4
6 3 6
6 4 5
6 5 4
6 6 3] ;
[B,idx] = sort(A,2) ;
[C,ia,ib] = unique(B,'rows') ;
C

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by