MATLAB: Does the loop not work for the increment stated

for looploops

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.

Best Answer

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