For Loop Increment Value

조회 수: 50 (최근 30일)
HARSHVARDHAN SARAVANAKUMAR
HARSHVARDHAN SARAVANAKUMAR 2017년 2월 11일
댓글: HARSHVARDHAN SARAVANAKUMAR 2017년 2월 11일
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.

채택된 답변

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by