Borrar filtros
Borrar filtros

how to compare a single row with remaining all rows of a matrix?

15 visualizaciones (últimos 30 días)
my input matrix is v=[1 2 3 4 5;3 4 7 8 9;6 4 8 7 9;3 4 7 8 9;3 2 9 8 4]; I am taking second row alone. I have to compare it with all the remaining rows. How to do it. Suggest me simple code which has few lines.
  2 comentarios
Azzi Abdelmalek
Azzi Abdelmalek el 3 de Sept. de 2012
wha should be you result? a matrix?
Jan
Jan el 3 de Sept. de 2012
What have you tried so far? Which problems occurred? What does "compare" exactly mean?

Iniciar sesión para comentar.

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 3 de Sept. de 2012
Editada: Andrei Bobrov el 3 de Sept. de 2012
out = ismember(v,v(2,:),'rows');
  1 comentario
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran el 5 de Sept. de 2012
Your reply matches my requirement exactly. Thanks Andrei bobrov.. And I thank all the people who spend their time to answer my query.

Iniciar sesión para comentar.

Más respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 3 de Sept. de 2012
Editada: Azzi Abdelmalek el 3 de Sept. de 2012
v=[1 2 3 4 5;3 4 7 8 9;6 4 8 7 9;3 4 7 8 9;3 2 9 8 4]
v2=v(2,:);
comp=any(bsxfun(@minus,v,v2),2))
%the result:
comp=1 0 1 0 1
that means that fourth row (comp(4)=0) is equal to the second row
  1 comentario
Jacek
Jacek el 25 de Oct. de 2015
For the future generations: I tested both solutions and solution proposed by Azzi is much faster, exactly 9x faster in my application, what was very important for me (large-scale data structures reorganization).

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by