My code keeps coming up with "Index Exceeds Array Bounds" help?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Walter Roberson
2018년 4월 30일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!