for loop problem

1 visualización (últimos 30 días)
Mohammad Golam Kibria
Mohammad Golam Kibria el 11 de Oct. de 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?

Respuesta aceptada

Jan
Jan el 11 de Oct. de 2011
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

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by