remove duplicate rows from a matrix
Mostrar comentarios más antiguos
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.
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 16 de Ag. de 2016
uA = unique(A, 'rows', 'stable');
7 comentarios
Ananya Malik
el 16 de Ag. de 2016
Editada: Ananya Malik
el 16 de Ag. de 2016
Guillaume
el 16 de Ag. de 2016
"Does not work"
It does exactly what you asked. If it does not work that would be because no two rows are exactly identical. There may be some small differences between the values that matlab does not show by default.
uA = uniquetol(A, 'ByRows', true); %use default tolerance. You can specify your own
There is no 'stable' option for uniquetol. The returned rows will be ordered.
Ananya Malik
el 16 de Ag. de 2016
Editada: Walter Roberson
el 16 de Ag. de 2016
Ananya Malik
el 16 de Ag. de 2016
Walter Roberson
el 16 de Ag. de 2016
You have a row that begins with 5, but no output row that begins with 5. You have removed too much.
John Allen
el 14 de Ag. de 2020
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
el 14 de Ag. de 2020
[~, iA] = uniquetol(A, 'byrows', true);
A(sort(iA), :) %the unique rows, in the original order
Categorías
Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!