Is it possible to know if there duplicated element in an array with Matlab ?

1 回表示 (過去 30 日間)
Lucas S
Lucas S 2019 年 5 月 6 日
コメント済み: Lucas S 2019 年 5 月 6 日
Hello !
I would like to if it is possible to know if there are duplicated element in an array with matlab like this :
A = {'abc' 'def'
'abcdef' 'ghijk'}
B = {'abc' 'def'
'abcdef' 'abc'}
if there are duplicated element in A
warning()
else
do something
end
same with B
How can i do this ?
Thank you !
  2 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 5 月 6 日
Have you check here?
Lucas S
Lucas S 2019 年 5 月 6 日
Well i didn't checked but with this post i don't see how can i do the if statement with unique() function.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2019 年 5 月 6 日
編集済み: Walter Roberson 2019 年 5 月 6 日
if length(unique(A)) ~= numel(A)
Note: it is questionable as to whether this will produce the "right" answer if there are nan in the array. Sometimes people want all nan in an array to be treated the same way (identical nan), but there are theoretical reasons why nan ~= nan is true, and since that must be true for all nan in an array, then by some definitions, the nan are not duplicated elements (if they were duplicated then they would equal each other.)
  1 件のコメント
Lucas S
Lucas S 2019 年 5 月 6 日
Thanks you ! In my case there are no possibilties to have NaN elements in my arrays so it's good

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by