Is it possible to change the running index in a for cycle?

1 vue (au cours des 30 derniers jours)
Mr M.
Mr M. le 3 Juil 2018
for i = 1:10
if i == 3
i = i+2;
end
end

Réponses (2)

Tejas Jayashankar
Tejas Jayashankar le 3 Juil 2018
Hi,
Check out the following answer for a similar question:
Let me know if this helps.

Jan
Jan le 4 Juil 2018
This does not work in a for loop, but it works with while:
i = 1;
while i <= 10
disp(i)
if i == 3
i = i+2;
end
i = i + 1;
end
Alternatively:
for i = [1:3, 5:10]
disp(i)
end

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by