How to remove duplicate observations in a matrix after sorting it?
Show older comments
I have a matrix FINAL=[1001,4,5,2015;1002,4,5,2015;1001,4,10,2014;1003,4,10,2014]
I want to sort this matrix by col 1, col 4, col 2, col 3 (i.e. organize column 1 by date)
Then I want to keep only the first row of a unique value of column 1
Any advice?
Answers (1)
Jos (10584)
on 14 Apr 2016
FINAL=[1001,4,5,2015;1002,4,5,2015;1001,4,10,2014;1003,4,10,2014]
X = sortrows(FINAL,[1 4 2 3]) % not sure what you want here ...
[~,i] = unique(X(:,1))
OUT = X(i,:)
Categories
Find more on Shifting and Sorting 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!