Regsrding for loop with array

5 Ansichten (letzte 30 Tage)
Muruganandham Subramanian
Muruganandham Subramanian am 26 Mai 2012
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 Kommentar
Muruganandham Subramanian
Muruganandham Subramanian am 26 Mai 2012
for lm=1:100
if (~isempty(find(A == lm)))
%calcultion
end
end

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Wayne King
Wayne King am 26 Mai 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.

Weitere Antworten (1)

Muruganandham Subramanian
Muruganandham Subramanian am 26 Mai 2012
Hi wayne, This also works!!! for lm=1:100 if (~isempty(find(A == lm))) %calcultion end end
  1 Kommentar
Wayne King
Wayne King am 26 Mai 2012
Hi, sorry! I didn't see your comment above :)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by