variable is not recognized from other function

조회 수: 2 (최근 30일)
Craig Johnson
Craig Johnson 2023년 5월 2일
댓글: Stephen23 2023년 5월 3일
Unrecognized function or variable 'Mi'.
Error in FourStrokeCycle (line 40)
Mbar=Mi*nin(1)/nin
function [pa,Ta,sa,cpi,Mi,nin] = AirProperties()
AirMatrix= readmatrix('AirProperties.xlsx');
pa=101325
Ta=273
sa=3796
cpi= AirMatrix(3,:)
Mi= AirMatrix(2,:)
nin= AirMatrix(1,:)
end
function [therm,chem,r_c,mfuel,mC02,ddt] = FourStrokeCycle(D,d,rpm,fuel,N)
fuel=0;
fuel= FuelProperties(fuel);
airprop= AirProperties();
%test inputs
rpm=1500
d=.02
N=6
V0=0.00006
L=0.1
D=0.02
PhiI=pi/6
PhiE=pi/6
omega= rpm* 0.10472
% convert rpm to omega rad/s
k=[1:1:N+1]
PhiK=(k-1)*(4*pi)/N
tK=(k-1)*(4*pi)/(N*omega)
PhiT= omega.*tK
x=(D/2)*cos(PhiT)+sqrt(((4*L^2)/D^2)-sin(PhiT).^2)
Vt= V0+(pi.*d^2)./4.*(L+(D./2)-x)
r_c= (V0+D*(pi*d^2)/4)/V0
therm = zeros(8,N+1)
P=zeros(1,N+1)
T=zeros(1,N+1)
P(1)=101325
Ru=8.3145
Mbar=Mi*nin(1)/nin

채택된 답변

Walter Roberson
Walter Roberson 2023년 5월 3일
function [pa,Ta,sa,cpi,Mi,nin] = AirProperties()
You define AirProperties as returning six separate outputs.
airprop= AirProperties();
When you call AirProperties, you only assign the first output to anything. airprop is going to become that value that was assigned to pa inside AirProperties() .
MATLAB is not going to say, "Oh, there are another 5 outputs, I guess I will assign them to variables with the same name as the names in the output list of the function that was called!" . When you have a potential output and the calling function does not assign it to a variable (or, in the case of the first output, use the value in an expression), then the output is simply discarded
If you want to get at the Mi that was returned by AirProperties() then when you call AirProperties you need to assign it to a variable. For example,
[airprop, ~, ~, ~, Mi, ~] = AirProperties();

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by