remove duplicate rows from a matrix
33 次查看(过去 30 天)
显示 更早的评论
I have a matrix of the form
A=[317.0000 282.0000 310.0000 259.0000 257.0000 305.0000 294.6667 282.0000
317.0000 282.0000 309.0000 372.0000 257.0000 305.0000 294.3333 319.6667
317.0000 282.0000 257.0000 305.0000 310.0000 259.0000 294.6667 282.0000
317.0000 282.0000 257.0000 305.0000 309.0000 372.0000 294.3333 319.6667
92.0000 166.0000 55.0000 235.0000 71.0000 173.0000 72.6667 191.3333
92.0000 166.0000 71.0000 173.0000 55.0000 235.0000 72.6667 191.3333];
I want to remove the redundant rows from A. Can anyone help. TIA.
0 个评论
采纳的回答
Thorsten
2016-8-16
unique(sort(A,2), 'rows')
2 个评论
John Allen
2020-8-14
warning, if position in the row is important then you dont want this. ie if (1,2) is different to (2,1)
更多回答(1 个)
Walter Roberson
2016-8-16
uA = unique(A, 'rows', 'stable');
7 个评论
John Allen
2020-8-14
the post title is misleading - you don't want to remove duplicate rows, you want to remove rows with the same contents, irrespective of order
Walter Roberson
2020-8-14
[~, iA] = uniquetol(A, 'byrows', true);
A(sort(iA), :) %the unique rows, in the original order
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!