필터 지우기
필터 지우기

For loop if else if statement not working

조회 수: 1 (최근 30일)
Austen Thomas
Austen Thomas 2018년 2월 16일
답변: Use 2018년 8월 7일
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