How do I determine if a value is unique within an iteration?

I have an array nuc. During an iteration from i:some value, If nuc(1,i) is unique, I want to proceed. In other words, when i is generated, and nuc(1,i) is determined, if it is the only one of that value in nuc, then...

 採用された回答

Joseph Cheng
Joseph Cheng 2014 年 3 月 27 日
編集済み: Joseph Cheng 2014 年 3 月 27 日

0 投票

You can use length(find(nuc(1,i)==nuc))>1 to see if it is not unique. Since you already have defined nuc(1,i) within nuc then obviously there will be atleast 1 instance it in.
if length(find(nuc(1,i)==nuc))==1
%dosomething
else
%break or return
end
or
if length(find(nuc(1,i)==nuc))~=1
%break or return
end

1 件のコメント

Rene
Rene 2014 年 3 月 28 日
Thank you. That is exactly what I was looking for.

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

その他の回答 (1 件)

Jos (10584)
Jos (10584) 2014 年 3 月 27 日

0 投票

Doe the array nut changes during iterations? If not, you can find the unique indices into nut using UNIQUE
[~,idx] = unique(nuc)
for i=idx
disp(i) ;
end
Otherwise
for i=1:N,
if sum(nuc==nuc(i))==1,
disp(i) ;
end
end

カテゴリ

ヘルプ センター および File ExchangeVehicle Dynamics Blockset についてさらに検索

タグ

質問済み:

2014 年 3 月 27 日

コメント済み:

2014 年 3 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by