Why does the loop not work for the increment stated?

2 vues (au cours des 30 derniers jours)
Hariyali Ramesh
Hariyali Ramesh le 14 Nov 2018
Commenté : Star Strider le 14 Nov 2018
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.

Réponse acceptée

Star Strider
Star Strider le 14 Nov 2018
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 commentaires
Hariyali Ramesh
Hariyali Ramesh le 14 Nov 2018
I tried again and that's what I got. Thanks for the help.
Star Strider
Star Strider le 14 Nov 2018
@Stephen — Thank you.
@Hariyali Ramesh — If my Answer helped you solve your problem, please Accept it!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by