필터 지우기
필터 지우기

How to fix: "Index exceeds matrix dimension"

조회 수: 2 (최근 30일)
Sanzhar Januzakov
Sanzhar Januzakov 2018년 2월 16일
편집: Shounak Shastri 2018년 2월 16일
Please help, trying to run while loop but it says that "Index exceeds matrix dimension" in "while(H(i)>Ha)". Guess I have a problem with increment and the size of Hs. Thank you in advance.
% Input Data
As = 5; % cross-sectional area of the spacecraft (m^2)
Ap = 150; % parachute area (m^2)
Hs = 150; % initial height (km)
U = 0; % initial velocity (m/s)
Hp = 3; % parachute deployment height (km)
Ha = 100; % height of the atmosphere above the earth (km)
M = 850; % mass of the spacecraft (kg)
C = 0.7; % drag coefficient
Tstep = 0.1; % time step (s)
% Increment initialisation
i=1; H(i)=Hs; v(i)=0; s(i)=0; t(i)=0;
%freefall without atmosphere
while(H(i)>Ha)
FD=0;
g(i) = (40*10^7)/(6371+H(i))^2;
a(i) = g(i); % As FD = 0
s(i+1)= U*Tstep + 0.5*a(i)*(Tstep^(2));
v(i+1)= U + a(i)*Tstep;
i=i+1; continue
end

채택된 답변

Shounak Shastri
Shounak Shastri 2018년 2월 16일
편집: Shounak Shastri 2018년 2월 16일
You are not updating H(i+1) in your while loop.
"i=1; H(i)=Hs;"
This line creates an array named "H" of size [1, 1] which has one value "Hs". In your loop, you are not doing anything to the array which would increase the size of "H".
I don't know what you are trying to do with the code but I am guessing you might want to do
H(i+1) = H(i) - s(i)
This will increase the size of your array and the loop would run till H(i) > Hs.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by