Check if there are repeated elements in a vector

Hi to all, is there a command to check if there are repeated elements in a vector; I just have to check in an "if"...
thanks a lot
Max

 Respuesta aceptada

Image Analyst
Image Analyst el 4 de Dic. de 2012
if length(v) == length(unique(v))
% There are no repeats.
.......

6 comentarios

Max
Max el 4 de Dic. de 2012
Yes, just this! Thanks
Michael Masry
Michael Masry el 16 de Abr. de 2019
And How to know their indices ?
Thanks
This Was a perfect answer
Thank you.
How would you restrict this to only check for V amount of values? Like if a vector has 6 of the same number, how does it work so that it doesn't work if I'm only checking for 3 of the same number? Does that make sense?
Yasir Iqbal
Yasir Iqbal el 25 de Nov. de 2021
You can simply craete a copy of the vector with the required amount of values. There can be other ways around also. Just a suggestion.
Image Analyst
Image Analyst el 25 de Nov. de 2021
@Larissa Monjaraz I don't understand because you forgot to provide your example with actual numbers. So about all I can say is to try ismember().

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

Max
el 4 de Dic. de 2012

Comentada:

el 25 de Nov. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by