Index exceeds number of array elements
古いコメントを表示
here's my code - when i run it i get "index exceeds number of array elements" at line 7 but there's 7 elements in temp so im not sure why im getting the error?
altitude = 0.0; 11.0; 20.0; 32.0; 47.0; 51.0; 71.0;
lapse_rate = -6.5; 0.0; 1.0; 2.8; 0.0; -2.8; -2.0;
temp = 288; 0; 0; 0; 0; 0; 0;
% t(n+1) = t(n) + altitude*lapse rate
for i = 1:7
j = i+1;
temp(j) = temp(i)+altitude(j)*lapse_rate(j);
end
temp
1 件のコメント
Torsten
2022 年 4 月 3 日
if i = 7, j is 8. The arrays you defined have only 7 elements. So the index exceeds the number of array elements for j=8 (8 is greater than 7).
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!