I got a code from my professor as an answer to one of our recitation problems and I am trying to decipher it.
조회 수: 1 (최근 30일)
이전 댓글 표시
The for loop is as follows:
p=1;
q=1;
for i=2:2:2*N
K(i,q:q+2)=[x(p)^2 x(p) 1];
L(i)=y(p);
p=p+1;
K(i+1,q:q+2)=[x(p)^2 x(p) 1];
L(i+1)=y(p);
q=q+3;
end
what is the "i=2:2:2*N" part? I thought you only used an i = n:m sort of format. Why are there two colons here? Thank you.
댓글 수: 1
답변 (2개)
David Hill
2020년 4월 14일
i=2:2:2*N;%advances i by 2 starting at 2 and going until it reaches 2*N
댓글 수: 0
Steven Lord
2020년 4월 14일
See the Description section on the documentation page for the for keyword. The array over which for iterates can be defined as a:b, but it can also be defined as a:d:b or it can be an arbitrary array over whose columns for should iterate.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!