My code keeps coming up with "Index Exceeds Array Bounds" help?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
n = 0;
t = 0;
deltat = 0.1;
m = 0.44;
Cd = 0.05;
p = 1.29;
Ra = 0.135;
%Find b using the rearranged formula for circumference of a circle.
b = 0.6/(pi()*2);
A = pi()*Ra*b;
% Pre set random values for testing code
x = [12,12,12];
deltat = [0.1];
agravity = [0,0,-9.81];
v = [2,2,2];
vwind = [3,1,2];
vdrag = [2,1,2];
fdrag = [3,2,3];
while x<=100
n = n + 1;
t(n+1) = t(n) + deltat;
x(n+1) = x(n) + v(n).*deltat;
v(n+1) = v(n) + (agravity(n).*deltat);
end
0 comentarios
Respuestas (1)
Walter Roberson
el 30 de Abr. de 2018
You have
agravity = [0,0,-9.81];
so agravity is length 3. You are not storing new agravity entries as you go along like you are for t, x, v, so when you reach n = 4, agravity(n) will be an error.
2 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!