How do i delete a repeating row
1 次查看(过去 30 天)
显示 更早的评论
Hello guys
I am trying to delete rows that has the same string value in collumn 1, but when I run the script nothing changes. Does anybody know what is wrong?
0 个评论
采纳的回答
Cris LaPierre
2022-5-7
Modified from this example
[C,ia] = unique(grades{:, 1});
B = grades(ia,:)
0 个评论
更多回答(1 个)
Image Analyst
2022-5-7
Try this. Adapt as needed
m = [1,2,3;4,5,6;4,5,6;7,8,9]
diffRows = diff(m, 1)
% Delete second row if it's a duplicate and adjacent.
rowsToDelete = find(all(diffRows == 0, 2)) + 1
m(rowsToDelete, :) = []
% Alternatively delete first row if it's a duplicate and adjacent.
% rowsToDelete = find(all(diffRows == 0, 2))
% m(rowsToDelete, :) = []
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!