How do I delete repetitions of rows in a matrix?
显示 更早的评论
Suppose I have the following matrix (the one I'm working on has 1000x1000 cells, so I'll simplify things):
a=[1,2,3; 8,7,8; 1,2,3; 5,6,0; 2,5,7; 2,5,7];
I want to get rid of rows that repeat themselves, so that I have one row left from each repetition set. The desired matrix in this case would be:
a=[1,2,3; 8,7,8; 5,6,0; 2,5,7];
How do I do this?
采纳的回答
更多回答(1 个)
Andrei Bobrov
2015-5-7
out = unique(A,'rows','stable');
old version of MATLAB:
[~,b] = unique(A,'rows','first');
out = A(sort(b),:);
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!