Delete unique element in column

11 views (last 30 days)
Mate 2u
Mate 2u on 29 Jun 2012
Edited: Miguel L on 27 Dec 2015
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 Comments
Miguel L
Miguel L on 27 Dec 2015
Edited: Miguel L on 27 Dec 2015
¡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.

Sign in to comment.

Accepted Answer

Jan
Jan on 29 Jun 2012
What about:
unique(x, 'rows')
?
  1 Comment
Ryan
Ryan on 29 Jun 2012
A = [1 2; 1 3; 3 4];
unique(A,'rows')
ans =
1 2
1 3
2 4

Sign in to comment.

More Answers (1)

Ryan
Ryan on 29 Jun 2012
Edited: Ryan on 29 Jun 2012
Based off of Jan's answer:
A = [1 2; 1 3; 3 4];
[B, I, J] = unique(A(:,1),'last');
NewMatrix = A(I,:);

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by