Delete unique element in column

조회 수: 4 (최근 30일)
Mate 2u
Mate 2u 2012년 6월 29일
편집: Miguel L 2015년 12월 27일
Hi I have a 25,000,000x2 matrix. I want to delete all Rows which have the same elements in column 1. So I would require only unique elements in column 1 and their corresponding values in column 2.
  댓글 수: 3
Jan
Jan 2012년 6월 29일
편집: Jan 2012년 6월 29일
Mate 2u has written as comment to my wrong answer:
Hi Jan for [1,2; 1,3; 3,4] we would expect to see => [1,3; 3,4] as 1 occured more than once (take the last of the non unique values).
This means, that he does not "want to delete all Rows which have the same elements in column 1".
Miguel L
Miguel L 2015년 12월 27일
편집: Miguel L 2015년 12월 27일
¡Hello Jan!
Regarding to this question, actually I wanna get "a = [1,2; 1,3; 3,4] => [3,4] ", as you suggest at first ¿Could you help me? Tank you in advance.

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

채택된 답변

Jan
Jan 2012년 6월 29일
What about:
unique(x, 'rows')
?
  댓글 수: 1
Ryan
Ryan 2012년 6월 29일
A = [1 2; 1 3; 3 4];
unique(A,'rows')
ans =
1 2
1 3
2 4

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

추가 답변 (1개)

Ryan
Ryan 2012년 6월 29일
편집: Ryan 2012년 6월 29일
Based off of Jan's answer:
A = [1 2; 1 3; 3 4];
[B, I, J] = unique(A(:,1),'last');
NewMatrix = A(I,:);

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by