フィルターのクリア

Calculation does not work, and it says "Index exceeds the number of array elements"

2 ビュー (過去 30 日間)
RetiredCheetoXI
RetiredCheetoXI 2022 年 2 月 6 日
回答済み: Cris LaPierre 2022 年 2 月 6 日
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)

回答 (1 件)

Cris LaPierre
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

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by