Function doesn't work in another file
조회 수: 6 (최근 30일)
이전 댓글 표시
Hello!
I have problem, i'm trying to to make function working in another file, but i always have this error:
Error in wysokosc (line 6)
[Th(i), Ph(i), Roh(i)]= atmosfera_wzorcowa(H(i));
I don't know how to fix it. Somebody can tell me where i make mistake?
Here i put my function:
function [Th, Ph, Roh] = atmosfera_wzorcowa(H)
g = 9.80665;
R = 287.05287;
if H>=0 & H<=11000
beta = -0.0065;
Tb = 288.15;
Pb = 101325;
Hb = 0;
Th=Tb+beta*(H-Hb);
Ph=Pb*((1+((beta/Tb)*(H-Hb)))^(-g/(beta*R)))
Roh = Ph1/(R*Th);
elseif H>11000 & H<=20000
beta = 0;
Tb = 216.65;
Pb = 22632;
Hb = 11000;
Th=Tb+beta*(H-Hb);
Ph=Pb*exp(-g/(R*Th)*(H-Hb))
else
disp('Wprowadzono zle dane')
end
Roh = Ph/(R*Th);
end
and my file
clear
clc
H = 0:1000:20000;
n = length(H);
for i = 1:n
[Th(i), Ph(i), Roh(i)]= atmosfera_wzorcowa(H(i));
end
댓글 수: 0
채택된 답변
Cris LaPierre
2021년 11월 13일
When I run your code, I get the following error:
Unrecognized function or variable 'Ph1'.
Roh = Ph1/(R*Th);
Is that just a typo? Should your equation be using Ph instead of Ph1? When I change it to be Ph, your code runs for me.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!