Function doesn't work in another file

7 次查看(过去 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

采纳的回答

Cris LaPierre
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 CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by