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?

for loop problem

Asked by Mohammad Golam Kibria

Mohammad Golam Kibria

on 11 Oct 2011
Accepted Answer by Jan

Jan

for i=1:a:20

    idx=find(consecutiveDiff(:,1)==val(i));
    a=numel(idx);

end

i need to increment the value i as the value of a is changed. in first execute if a=5 the value of i becomes 2 not 1+5=6 . why ? can any body help?

0 Comments

Mohammad Golam Kibria

Mohammad Golam Kibria

Tags

Products

No products are associated with this question.

1 Answer

Answer by Jan

Jan

on 11 Oct 2011
Accepted answer

when the line for i = 1:a:20 is executed it uses the value of a as it is then known, which is probably 1.

You will need something like this:

i = 1;
while i<=20
  idx = find(consecutiveDiff(:,1)==val(i));
  a = numel(idx);
  i = i + a;
end

0 Comments

Jan

Jan

Contact us