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

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

for loop problem

Asked by Mohammad Golam Kibria on 11 Oct 2011

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

Tags

Products

No products are associated with this question.

1 Answer

Answer by 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

Contact us