Borrar filtros
Borrar filtros

how can i find identical rows in a matrix

135 visualizaciones (últimos 30 días)
AA
AA el 21 de Mzo. de 2015
Comentada: AA el 21 de Mzo. de 2015
I have a 158x7 matrix. I want to find if there is at least one row which is identical.
  2 comentarios
Geoff Hayes
Geoff Hayes el 21 de Mzo. de 2015
AA - please describe what you mean by similar. Do you meant that the two rows are identical or share the same values or share a pattern of numbers? Be clear about what the problem is you are trying to solve. Use the question body to include more than just a repeat of your question header.
AA
AA el 21 de Mzo. de 2015
ok i changed the question. thanks for the advice

Iniciar sesión para comentar.

Respuesta aceptada

Konstantinos Sofos
Konstantinos Sofos el 21 de Mzo. de 2015
Editada: Konstantinos Sofos el 21 de Mzo. de 2015
Use unique() to find the distinct row values. If you end up with fewer rows, there are duplicates. It'll also give you indexes of one location of each of the distinct values. All the other row indexes are your duplicates.
x = [
1 1
2 2
3 3
4 4
2 2
3 3
3 3
];
[u,I,J] = unique(x, 'rows', 'first')
hasDuplicates = size(u,1) < size(x,1)
ixDupRows = setdiff(1:size(x,1), I)
dupRowValues = x(ixDupRows,:)

Más respuestas (1)

Star Strider
Star Strider el 21 de Mzo. de 2015
Use the unique function with the 'rows' option.
  2 comentarios
AA
AA el 21 de Mzo. de 2015
would it be possible to give me an example?
AA
AA el 21 de Mzo. de 2015
B = unique(A,'rows');
As a check, if size(B) ~= size(A), then you have at least two identical rows.

Iniciar sesión para comentar.

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by