For Loop Increment Value

68 Ansichten (letzte 30 Tage)
HARSHVARDHAN SARAVANAKUMAR
HARSHVARDHAN SARAVANAKUMAR am 11 Feb. 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.

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by