Why does the loop not work for the increment stated?

조회 수: 3 (최근 30일)
Hariyali Ramesh
Hariyali Ramesh 2018년 11월 14일
댓글: Star Strider 2018년 11월 14일
for t= 0:1:20
a= [t, sin(t), 0];
b= [0, 0, cos(t)];
v= a + b;
end
The loop only calculates the value of v for 20, not 0 to 20 as stated by the increment. What have I done wrong? I need it to calculate the vector v for numbers 0 all the way to 20.

채택된 답변

Star Strider
Star Strider 2018년 11월 14일
Your code is essentially correct. If you want all the itermediate results, you need to index ‘v’:
for t= 0:1:20
a= [t, sin(t), 0];
b= [0, 0, cos(t)];
v(t+1,:)= a + b;
end
  댓글 수: 4
Hariyali Ramesh
Hariyali Ramesh 2018년 11월 14일
I tried again and that's what I got. Thanks for the help.
Star Strider
Star Strider 2018년 11월 14일
@Stephen — Thank you.
@Hariyali Ramesh — If my Answer helped you solve your problem, please Accept it!

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

추가 답변 (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