MATLAB: Storing Values From a Loop

loopsmatrix

I'm doing a project involving an implementation of Euler's method for class, and am using a "for" loop to increment my values. The code below runs, but whatever new y value I get is overwritten as the loop goes through. I need to be able to save those y values after each time through the loop and put them into a matrix so that they can later be graphed. I'm not sure how to do this, so any help is appreciated!
a=1250
q=500
c=160
n=0.5
y=1.1
for t=0:n:2
s=3*(q/a)*sin(t)^2-(c*(1+y)^1.5)/a
y=y+s
end
Thanks,
-Kyle

Best Answer

Replace
s=3*(q/a)*sin(t)^2-(c*(1+y)^1.5)/a
y=y+s
with
s=3*(q/a)*sin(t)^2-(c*(1+y(end))^1.5)/a;
y=[y y(end)+s];