For loop if else if statement not working

1 visualización (últimos 30 días)
Austen Thomas
Austen Thomas el 16 de Feb. de 2018
Respondida: Use el 7 de Ag. de 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');

Respuestas (2)

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

Iniciar sesión para comentar.


Use
Use el 7 de Ag. de 2018
Austen Thomas, have you solved this problem? I also got same problem.

Categorías

Más información sobre MATLAB Compiler en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by