[英]How get an output from a function in another function?
I have a function Matrices
that gives me Along
. 我有一个函数
Matrices
,让我Along
。 I want Along
from first function to pass another function MatricesElse
as an argument. 我想
Along
从第一功能通过另一个函数MatricesElse
作为参数。 This code has error, why? 这段代码有错误,为什么?
function theOutput = Matrices()
theOutput = Along;
function MatricesElse(Along)
disp(theInput); % // Will print value of Along returned from first function,
syms teta q u w Se Sth v p r o Y SR SA s
% // Aircraft Equations of Longitudinal Motion
Ilong=[1 0 0 0;0 1 0 0; 0 1 0 0;0 0 0 1];
Xlong=[teta;q;u;w];
Ulong=[Se;Sth];
Xlong=(inv(s*Ilong-Along))*Blong*Ulong;
teta=Xlong(1,1)
q=Xlong(2,1)
u=Xlong(2,1)
w=Xlong(3,1)
% // Aircraft Equations of Lateral Motion
Ilat=[1 0 0 0 0;0 1 0 0 0;0 0 1 0 0;0 0 0 1 0;0 0 0 0 1];
Xlat=[v;p;r;o;Y];
Ulat=[SR;SA];
Xlat=(inv(s*I-Alat))*Blat*Ulong;
v=Xlat(1,1)
p=Xlat(2,1)
r=Xlat(3,1)
o=Xlat(4,1)
Y=Xlat(5,1)
end
Short explanation: you are trying to call a private variable of function Matrices()
outside of this function, that's why it doesn't work. 简短说明:您正在尝试在此函数之外调用函数
Matrices()
的私有变量,这就是为什么它不起作用的原因。
This code should work. 此代码应该起作用。 Note that the name
CalcMatrix
can differ from theOutput
and Along
, but all of these variables have the same content: 需要注意的是名字
CalcMatrix
可以从不同theOutput
和Along
,但所有这些变量都具有相同的内容:
function main
CalcMatrix = Matrices()
MatricesElse(CalcMatrix)
function theOutput = Matrices()
theOutput = Along;
function MatricesElse(Along)
disp(theInput); % // Will print value of Along returned from first function,
syms teta q u w Se Sth v p r o Y SR SA s
% // Aircraft Equations of Longitudinal Motion
Ilong=[1 0 0 0;0 1 0 0; 0 1 0 0;0 0 0 1];
Xlong=[teta;q;u;w];
Ulong=[Se;Sth];
Xlong=(inv(s*Ilong-Along))*Blong*Ulong;
teta=Xlong(1,1)
q=Xlong(2,1)
u=Xlong(2,1)
w=Xlong(3,1)
% // Aircraft Equations of Lateral Motion
Ilat=[1 0 0 0 0;0 1 0 0 0;0 0 1 0 0;0 0 0 1 0;0 0 0 0 1];
Xlat=[v;p;r;o;Y];
Ulat=[SR;SA];
Xlat=(inv(s*I-Alat))*Blat*Ulong;
v=Xlat(1,1)
p=Xlat(2,1)
r=Xlat(3,1)
o=Xlat(4,1)
Y=Xlat(5,1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.