Calculation does not work, and it says "Index exceeds the number of array elements"
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to calculate temperature, with an imput of "h". And based on the input it would use a certain value for a. It is not working properly and is saying "Index exceeds the number of array elements." I am also trying to make this I can call in another code, and I am not sure if this is the correct way to go about doing that
function [h, a] = Temperature(T)
prompt = 'Altitude (m) ';
h = input(prompt);
if (h <= 11000)
a = -6.5e-3;
elseif (h <= 25000)
a = 1;
elseif (h <= 47000)
a = 3e-3;
elseif (h <= 53000)
a = 1;
elseif (h <= 79000)
a = -4.5e-3;
elseif (h <= 90000)
a = 1;
elseif (h <= 110000)
a = 4e-3;
end
T = 273.15 + a(h)
0 commentaires
Réponses (1)
Cris LaPierre
le 6 Fév 2022
The error is caused by this code at the bottom of your function: a(h)
Your variable a only contains a single number, so there is no reason to index it using h. Try just adding a.
T = 273.15 + a
0 commentaires
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!