Index exceeds number of array elements
Afficher commentaires plus anciens
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 commentaire
Torsten
le 3 Avr 2022
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).
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!