compare elements in rows of a matrix
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I have the following matrix:
a=[1 2 3 9; 2 2 3 1; 3 3 3 3]
is there a function that compares the elements of every row?
Something that tells me if they are all different or all the same.
I would like to get
out=[1 0 0]
or
out=[0 0 1]
thanks,
michele
0 comentarios
Respuesta aceptada
Walter Roberson
el 28 de Nov. de 2011
One way:
all(diff(a,1,2)==0,2)
2 comentarios
Walter Roberson
el 29 de Nov. de 2011
Thanks for catching that -- I didn't know that. I have edited to fix.
Más respuestas (1)
Ver también
Categorías
Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!