I want to create a movie with a for loop, but Index exceeds the number of array elements (1) is shown. Someone can tell me were is the error? The for loop without the condition works fine, but where i assign a condition, the error message appears. 🙁 I just want that when y <= 0, the angle theta0 and v0 change to theta0 = atan(y(j-2)/(x(j)-x(j-2))) and v0 = 0.8v0.
clear, clcg=9.81; theta0=45*pi/180; v0=5;t(1)=0;x=0;y=0;plot(x,y,'o','MarkerFaceColor','b','MarkerSize',8)axis([0 8 0 0.8])M(1)=getframe;dt=1/128;for j = 2:1000 t(j)=t(j-1)+dt; x=v0*cos(theta0)*t(j); y=v0*sin(theta0)*t(j)-0.5*g*t(j)^2; plot(x,y,'o','MarkerFaceColor','b','MarkerSize',8); axis([0 8 0 0.8]); M(j)=getframe; if y<=0 theta0 = atan(y(j-2)/(x(j)-x(j-2))); v0 = 0.8*v0; plot(x(j),0,'o','MarkerFaceColor','b','MarkerSize',8) M(j) = getframe; endendpausemovie(M,1)
Best Answer