For loop if else if statement not working

1 次查看(过去 30 天)
I am trying to make a graph where two different sets of equations need to be used at different h values but i keep getting the error code "Undefined function 'h' for input arguments of type 'double'"
can anyone correct my code and explain to me why this is wrong? Thanks
g=32.2;
R=1716;
a=-0.003563;
x = g./(a.*R);
y = g/R;
T_SSL=518.69;
rho_SSL=0.002377;
hv = 1:50:45000;
for i = 1:numel(hv)
if (h(i) <= 36152)
% lower then 36152
h(i) = hv(i);
T(i) = T_SSL+a*h(i);
rho(i) = rho_SSL*((T(i)/T_SSL)^-(x+1));
TH(i) = 6647034.077*rho(i);
elseif(h(i) > 36152)
% for over 36152 ft
h(i) = hv(i);
T(i) = 389.7;
rho(i) = rho_SSL*exp(-(y/T(i))*h(i));
TH(i) = 6647034.077*rho(i);
end
end
plot (h,TH);
xlabel('Altitude (ft)');
ylabel('Power Avaiable (hp)');
title('Power Avaiable vs Altitude');

回答(2 个)

KSSV
KSSV 2018-2-16
g=32.2;
R=1716;
a=-0.003563;
x = g./(a.*R);
y = g/R;
T_SSL=518.69;
rho_SSL=0.002377;
hv = 1:50:45000;
for i = 1:numel(hv)
if (hv(i) <= 36152)
% lower then 36152
h(i) = hv(i);
T(i) = T_SSL+a*h(i);
rho(i) = rho_SSL*((T(i)/T_SSL)^-(x+1));
TH(i) = 6647034.077*rho(i);
elseif(hv(i) > 36152)
% for over 36152 ft
h(i) = hv(i);
T(i) = 389.7;
rho(i) = rho_SSL*exp(-(y/T(i))*h(i));
TH(i) = 6647034.077*rho(i);
end
end
plot (h,TH);
xlabel('Altitude (ft)');
ylabel('Power Avaiable (hp)');
title('Power Avaiable vs Altitude');
Variable should be hv not h. Code need to be tuned a lot.
  1 个评论
Austen Thomas
Austen Thomas 2018-2-16
Thanks! I am relatively new to matlab if you could give me any pointers it would be appreciated

请先登录,再进行评论。


Use
Use 2018-8-7
Austen Thomas, have you solved this problem? I also got same problem.

类别

Help CenterFile Exchange 中查找有关 MATLAB Compiler 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by