Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Regsrding for loop with array

Asked by Muruganandham Subramanian

Muruganandham Subramanian

on 26 May 2012
Accepted Answer by Wayne King

Wayne King

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 Comment

Muruganandham Subramanian

Muruganandham Subramanian

on 26 May 2012

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

Muruganandham Subramanian

Muruganandham Subramanian

Products

No products are associated with this question.

2 Answers

Answer by Wayne King

Wayne King

on 26 May 2012
Accepted answer
   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.

0 Comments

Wayne King

Wayne King

Answer by Muruganandham Subramanian

Muruganandham Subramanian

on 26 May 2012

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

1 Comment

Wayne King

Wayne King

on 26 May 2012

Hi, sorry! I didn't see your comment above :)

Muruganandham Subramanian

Muruganandham Subramanian

Contact us