For Loop Increment Value

56 vues (au cours des 30 derniers jours)
HARSHVARDHAN SARAVANAKUMAR
HARSHVARDHAN SARAVANAKUMAR le 11 Fév 2017
I am beginner in MATLAB. I want to write a for loop where the increment value should increase by 2.
For eg:
for i = 1:9
something
end
The value of i should be 1, 3, 5, 7, 9. Kindly help.

Réponse acceptée

Geoff Hayes
Geoff Hayes le 11 Fév 2017
Just do
for k=1:2:9
% do something
end
where we have defined the step size to be two.
  1 commentaire
HARSHVARDHAN SARAVANAKUMAR
HARSHVARDHAN SARAVANAKUMAR le 11 Fév 2017
Thank you. I feel silly. This was easy.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by