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!