Array indices must be positive integers or logical values.

2 ビュー (過去 30 日間)
Adeola Badejo
Adeola Badejo 2020 年 4 月 23 日
回答済み: Image Analyst 2020 年 4 月 23 日
dt = 0.1;
t = 0.1:dt:1000;
V = zeros(1, length(t));
m = zeros(1, length(t));
h = zeros(1, length(t));
p = zeros(1, length(t));
for n=2:length(t)
p(n) = 1.225*10^(3.*h(n)/50000);
h(n) = h(n-1) + 0.5*(V((n)*dt)+ V((n-1)*dt));
V(n) = (V_e/dt)*(1-(n*dt)/(m(n-1)*dt)) - (G*M)/(h(n-1)*dt + R).^2 + (p(n)*A*V(n-1)^2*dt*C_d*dt/(m(n-1)*dt) + 1);
end
i keep getting an error on the second line that wont allow my code to run so i made every changing value (p,h and n) arrays of length t but it still didnt work and i dont know how to get rid of the error message.
  2 件のコメント
Ken Boydstun
Ken Boydstun 2020 年 4 月 23 日
I had a similar problem which I avoided by changing the index value n to an integer.
Adeola Badejo
Adeola Badejo 2020 年 4 月 23 日
sorry which n exactly? do you mean the definitive n on the for line?

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2020 年 4 月 23 日
(n)*dt is not an integer, and it needs to be. Suggest you reexamine what you really want to do.

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by