필터 지우기
필터 지우기

remove duplicate rows from a matrix

조회 수: 37 (최근 30일)
Ananya Malik
Ananya Malik 2016년 8월 16일
댓글: Walter Roberson 2020년 8월 14일
I have a matrix of the form
A=[317.0000 282.0000 310.0000 259.0000 257.0000 305.0000 294.6667 282.0000
317.0000 282.0000 309.0000 372.0000 257.0000 305.0000 294.3333 319.6667
317.0000 282.0000 257.0000 305.0000 310.0000 259.0000 294.6667 282.0000
317.0000 282.0000 257.0000 305.0000 309.0000 372.0000 294.3333 319.6667
92.0000 166.0000 55.0000 235.0000 71.0000 173.0000 72.6667 191.3333
92.0000 166.0000 71.0000 173.0000 55.0000 235.0000 72.6667 191.3333];
I want to remove the redundant rows from A. Can anyone help. TIA.

채택된 답변

Thorsten
Thorsten 2016년 8월 16일
unique(sort(A,2), 'rows')
  댓글 수: 2
Ananya Malik
Ananya Malik 2016년 8월 16일
Thnaks a lot @Thorsten. Works perfectly.
John Allen
John Allen 2020년 8월 14일
warning, if position in the row is important then you dont want this. ie if (1,2) is different to (2,1)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2016년 8월 16일
uA = unique(A, 'rows', 'stable');
  댓글 수: 7
John Allen
John Allen 2020년 8월 14일
the post title is misleading - you don't want to remove duplicate rows, you want to remove rows with the same contents, irrespective of order
Walter Roberson
Walter Roberson 2020년 8월 14일
[~, iA] = uniquetol(A, 'byrows', true);
A(sort(iA), :) %the unique rows, in the original order

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by