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

1 view (last 30 days)
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.

Accepted Answer

Geoff Hayes
Geoff Hayes on 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.

More Answers (1)

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

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!