MATLAB: Array indices must be positive integers or logical values.

array

Hello,
My code below is displaying the following error message:
"Array indices must be positive integers or logical values.
Error in Assign5_Prob7 (line 38)
phi(i) = atand(tan(phi_o)+((g*t(i))/Vx_o)*((1/3)*((Vx_o/Vx(i)+ sqrt((Vx_o/Vx(i)))+1)))); "
I don't see anything resulting in a zero within the equation. I'm not sure why this error is displaying. Thank you.
Vy_o = 0.00001;
Vx_o = 2296;
phi_o = atand(Vx_o/Vy_o);
for i = 1:6
x(i) = (i-1)*200*3;
y(i) = (i-1)*200*3;
Vx(i) = (sqrt(Vx_o) - ((k3/2)*x(i)))^2;
t(i) = (x(i)/Vx_o)*sqrt(Vx_o/Vx(i));
phi(i) = atand(tan(phi_o)+((g*t(i))/Vx_o)*((1/3)*((Vx_o/Vx(i)+ sqrt((Vx_o/Vx(i)))+1))));

Best Answer

This error means that your index variable i is either
  • negative
  • zero
  • not an integer
Check your code that you did not include and see if you modify the value of i somewhere before getting to line 38.