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

 채택된 답변

Image Analyst
Image Analyst 2012년 12월 4일

11 개 추천

if length(v) == length(unique(v))
% There are no repeats.
.......

댓글 수: 6

Max
Max 2012년 12월 4일
Yes, just this! Thanks
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?
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.
@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().

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Simulink Check에 대해 자세히 알아보기

질문:

Max
2012년 12월 4일

댓글:

2021년 11월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by