Function doesn't work in another file
1 次查看(过去 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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!