Check if there are repeated elements in a vector

45 次查看(过去 30 天)
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
if length(v) == length(unique(v))
% There are no repeats.
.......
  6 个评论
Yasir Iqbal
Yasir Iqbal 2021-11-25
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 2021-11-25
@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 个)

类别

Help CenterFile Exchange 中查找有关 Operators and Elementary Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by