Regsrding for loop with array

Hi all, A=[1;3;5; 6]; for 1 to 100 iterations, if any element in array matches with the iteration,e.g .for 1st iteration A's 1st data is matching. else it should come out from the loop. Can u suggest me any idea?
Thanks

1 Commento

for lm=1:100
if (~isempty(find(A == lm)))
%calcultion
end
end

Accedi per commentare.

 Risposta accettata

Wayne King
Wayne King il 26 Mag 2012
for nn = 1:8
if(any(A==nn)),
disp('hi');
else
disp('bye');
end
end
Obviously, replace disp('hi') with your calculation and I've just shown this up to an index of 8.

Più risposte (1)

Muruganandham Subramanian
Muruganandham Subramanian il 26 Mag 2012

0 voti

Hi wayne, This also works!!! for lm=1:100 if (~isempty(find(A == lm))) %calcultion end end

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by