Calculation does not work, and it says "Index exceeds the number of array elements"
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Cris LaPierre
2022 年 2 月 6 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!