Basic loop syntax in MATLAB: for k=1:n

What does it mean
for k=1:n

댓글 수: 2

mohsen mohsen
mohsen mohsen 2021년 3월 29일
for i= 1:3
Walter Roberson
Walter Roberson 2021년 3월 29일
It is as described in the responses rom Sean and I, with n being 3.

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

답변 (2개)

Sean de Wolski
Sean de Wolski 2011년 1월 28일

2 개 추천

it means that everything between that line
k = 1:n
and
end
will be evaluated with k = every integer between 1 and n.
doc for
for more information
Walter Roberson
Walter Roberson 2011년 1월 28일

1 개 추천

(Adjusting Sean's answer):
it means that everything between that line
k = 1:n
and
end
will be evaluated with k = every integer starting at 1 and not exceeding n; no iterations will be done at all if n < 1
doc for
for more information

댓글 수: 4

Jan
Jan 2011년 1월 28일
편집: Jan 2017년 12월 30일
If you think Walter's adjustments are peantus, read: http://www.mathworks.com/matlabcentral/newsreader/view_thread/293533
Walter Roberson
Walter Roberson 2011년 1월 28일
Heh. Somehow I missed that discussion the first time around!
Matt Fig
Matt Fig 2011년 1월 28일
Jan, how do you remember these things! There are obviously no angry armadillos bouncing around in your head.

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2011년 1월 28일

댓글:

2021년 3월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by