For loop if else if statement not working

1 view (last 30 days)
Austen Thomas
Austen Thomas on 16 Feb 2018
Answered: Use on 7 Aug 2018
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');

Answers (2)

KSSV
KSSV on 16 Feb 2018
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 Comment
Austen Thomas
Austen Thomas on 16 Feb 2018
Thanks! I am relatively new to matlab if you could give me any pointers it would be appreciated

Sign in to comment.


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

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!