Function doesn't work in another file

조회 수: 6 (최근 30일)
Joanna Zajac
Joanna Zajac 2021년 11월 13일
댓글: Joanna Zajac 2021년 11월 13일
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.
  댓글 수: 1
Joanna Zajac
Joanna Zajac 2021년 11월 13일
You are right, i missed it. Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (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