Matrixr edundant rows removal

1 view (last 30 days)
Mohammad Farhat
Mohammad Farhat on 10 Jul 2018
Commented: Mohammad Farhat on 10 Jul 2018
I have this matrix: if two or more rows have the same first element, I want to keep only one of them
[ 0.93178465908684446928710074968855, -51.935229283138453086135436847359]
[ 0.22010754397902585905527489863535, 183.86152484784865583467899346115]
[ 0.70067697106846131579942122891388, 220.50586079939492722588263304992]
[ 0.39854749521549824161398289625791, -123.05156509529288636747906602897]
[ 0.84281396964448855914703169574105, -123.25794263558350273782337915136]
[ 0.055796871633806027844183498033979, -65.302512205148103987813108620342]
[ 0.22010754397902585905527489863535, 183.86152592899225091194324659587]
[ 0.22010754397902585905527489863535, 183.86152592899225091194324659587]
[ 0.70067697106846131579942122891388, -139.49413421794328676585602641615]
[ 0.22010754397902585905527489863535, -176.1384735539390731815390671223]

Accepted Answer

Paolo
Paolo on 10 Jul 2018
Edited: Paolo on 10 Jul 2018
newmatrix = oldmatrix(find(uniquetol(oldmatrix(:,1))),:)
  5 Comments
Paolo
Paolo on 10 Jul 2018
x = [ 0.93178465908684446928710074968855, -51.935229283138453086135436847359
0.22010754397902585905527489863535, 183.86152484784865583467899346115
0.70067697106846131579942122891388, 220.50586079939492722588263304992
0.39854749521549824161398289625791, -123.05156509529288636747906602897
0.84281396964448855914703169574105, -123.25794263558350273782337915136
0.055796871633806027844183498033979, -65.302512205148103987813108620342
0.22010754397902585905527489863535, 183.86152592899225091194324659587
0.22010754397902585905527489863535, 183.86152592899225091194324659587
0.70067697106846131579942122891388, -139.49413421794328676585602641615
0.22010754397902585905527489863535, -176.1384735539390731815390671223]
newmatrix = x(find(uniquetol(x(:,1))),:)
newmatrix =
0.9318 -51.9352
0.2201 183.8615
0.7007 220.5059
0.3985 -123.0516
0.8428 -123.2579
0.0558 -65.3025

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices 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!