Hello everyone, I keep getting the classic error message of 'Index exceeds the number of array elements (169)'. Here is my code, it's a very simple while loop:
syms T h
T (h) = ((288.19-0.00649.*h));
h = linspace (7620,11000,169); %Every step is 20m change in altitude
D = vpa(T(h),4);
s = 1;
while s <= 169
rho(s) = 1.225*(D(h)/288.19)^((9.80665/(0.0065*286))-1);
s = s+1;
end
I really don't see where I've gone wrong. I have other while loops that follow the same structure and they work perfectly. Any help would be appreciated. Thanks in advance!

 採用された回答

David Hill
David Hill 2021 年 4 月 1 日
編集済み: David Hill 2021 年 4 月 1 日

1 投票

No need for any loops. No need for symbolics.
h = linspace (7620,11000,169);
D = 288.19-0.00649.*h;
rho= 1.225*(D/288.19).^(9.80665/0.0065/286-1);

1 件のコメント

Juan Pardo Arazola
Juan Pardo Arazola 2021 年 4 月 2 日
Thanks! Works fine. Hadn't thought of not using a loop.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by