Eliminate a row where a column has repeated values

1 view (last 30 days)
Hi I have the following matrix
eliti =
Columns 1 through 8
0 0 1.0000 0 0 0 0 0
0 0 1.0000 0 0 0 0 0
0 1.0000 0 1.0000 1.0000 0 0 0
Columns 9 through 16
0 0 0 0 0 1.0000 1.0000 0
1.0000 1.0000 0 0 0 0 1.0000 0
0 0 0 0 0 0 1.0000 0
Columns 17 through 21
-24.0000 38.0000 10.0751 0.0413 0.2388
-52.0000 26.0000 11.1629 0.0458 0.6012
-24.0000 38.0000 10.0751 0.0413 0.3106
And I need to eliminate where there a repeated values in the 18th column so it will be like this eliti =
Columns 1 through 8
0 0 1.0000 0 0 0 0 0
0 1.0000 0 1.0000 1.0000 0 0 0
Columns 9 through 16
1.0000 1.0000 0 0 0 0 1.0000 0
0 0 0 0 0 0 1.0000 0
Columns 17 through 21
-24.0000 38.0000 10.0751 0.0413 0.2388
-52.0000 26.0000 11.1629 0.0458 0.6012

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 3 Jun 2016
[~,b] = unique(eliti(:,18),'stable');
eliti_new = eliti(b,:);

More Answers (1)

Chad Greene
Chad Greene on 3 Jun 2016
You can use the indices returned by unique to get the rows corresponding to unique values in column 18:
M = randi(5,[3 21])
[~,ia] = unique(M(:,18))
M_new = M(ia,:);

Categories

Find more on MATLAB 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!