How can I delete the repeated values and keep just a row of each one?

1 Ansicht (letzte 30 Tage)
I have this matrix
[3 11 43;
3 17 41;
3 41 17;
3 43 11;
11 3 43;
11 43 3;
17 3 41;
17 41 3;
41 3 17;
41 17 3;
43 3 11;
43 11 3 ]
The result should be something like this [ 3 11 43; 3 17 41 ]
OBS. I tried unique() and it didn't work as I want.

Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 18 Feb. 2019
DS - you could try
unique(sort(A,2), 'rows')
where A is the matrix that you have defined above. This could be inefficient though especially as your A gets larger. With this code, we sort all the columns for each row of A and then calll unique with rows so that each row is treated as a "single entity". See unique values in array for details.

Weitere Antworten (1)

madhan ravi
madhan ravi am 18 Feb. 2019
A = unique(sort(a,2),'rows') % where a is your matrix

Kategorien

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

Community Treasure Hunt

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

Start Hunting!

Translated by