Deleting duplicate rows and keeping zero rows?
Mostrar comentarios más antiguos
Hi! I need a help!
A=[1 2;
3 4;
0 0;
1 2;
5 6;
0 0]
How can i delete duplicate rows, without deleting zero rows? I want my new matrix to look like that:
A=[1 2;
3 4;
0 0;
5 6;
0 0]
Thank you very much! ;)
Respuesta aceptada
Más respuestas (1)
the cyclist
el 28 de En. de 2016
Here is another way.
zeroRowIndex = find(~any(A,2)); % Rows with all zeros
[~,uniqueRowIndex] = unique(A,'rows'); % Unique rows (including all-zero rows)
rowsToKeep = union(uniqueRowIndex,zeroRowIndex); % Combine the criteria. [union will discard duplicates by default]
B = A(rowsToKeep,:); % Output
1 comentario
Karmen
el 1 de Mzo. de 2016
Categorías
Más información sobre Variables en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!