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...

 Respuesta aceptada

Joseph Cheng
Joseph Cheng el 27 de Mzo. de 2014
Editada: Joseph Cheng el 27 de Mzo. de 2014
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

Más respuestas (1)

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

Categorías

Más información sobre Vehicle Dynamics Blockset en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 27 de Mzo. de 2014

Comentada:

el 28 de Mzo. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by