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?

 채택된 답변

Cris LaPierre
Cris LaPierre 2022년 5월 7일

0 개 추천

Modified from this example
[C,ia] = unique(grades{:, 1});
B = grades(ia,:)
See this page for alternate ways to access data in a table.

추가 답변 (1개)

Image Analyst
Image Analyst 2022년 5월 7일

0 개 추천

Try this. Adapt as needed
m = [1,2,3;4,5,6;4,5,6;7,8,9]
m = 4×3
1 2 3 4 5 6 4 5 6 7 8 9
diffRows = diff(m, 1)
diffRows = 3×3
3 3 3 0 0 0 3 3 3
% Delete second row if it's a duplicate and adjacent.
rowsToDelete = find(all(diffRows == 0, 2)) + 1
rowsToDelete = 3
m(rowsToDelete, :) = []
m = 3×3
1 2 3 4 5 6 7 8 9
% Alternatively delete first row if it's a duplicate and adjacent.
% rowsToDelete = find(all(diffRows == 0, 2))
% m(rowsToDelete, :) = []

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

릴리스

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by