Eliminate a row where a column has repeated values

조회 수: 1 (최근 30일)
Hansel Montuffar
Hansel Montuffar 2016년 6월 3일
답변: Andrei Bobrov 2016년 6월 3일
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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2016년 6월 3일
[~,b] = unique(eliti(:,18),'stable');
eliti_new = eliti(b,:);

추가 답변 (1개)

Chad Greene
Chad Greene 2016년 6월 3일
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,:);

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by