Hi i'm trying to run this function in simulink using matlab function block but i'm encountering this errors can anyone help me regarding this?

조회 수: 1 (최근 30일)
function y = LINEARKALMAN(u)
V=10;
if(u(7)==0)
X=[0.1807;0];
Pxx=[0.01 0;0 0.01];
else
X=X2;
Pxx=Pxy;
end
theta=X(1);
phi=X(2);
A=[0,- u(6)*cos(phi) - u(5)*sin(phi);u(6)*cos(phi)*(tan(theta)^2 + 1) + u(5)*sin(phi)*(tan(theta)^2 + 1), u(5)*cos(phi)*tan(theta) - u(6)*sin(phi)*tan(theta)];
B=[0,cos(phi),-sin(phi);1, sin(phi)*tan(theta), cos(phi)*tan(theta)];
C=[cos(theta) + (100*V*u(5)*cos(theta))/981,0; sin(phi)*sin(theta) - (100*V*(u(4)*cos(theta) + u(6)*sin(theta)))/981, -cos(phi)*cos(theta); cos(phi)*sin(theta), cos(theta)*sin(phi) + (100*V*u(5)*sin(phi))/981];
R=[0.0016 0 0;0 0.0016 0;0 0 0.0016];
Q=[0.001 0;0 0.001];
phik=expm(A.*0.01);
v=[u(4);u(5);u(6)];
Y=[u(1);u(2);u(3)];
X1=phik*X+B*v;
Inno=Y-C*X1;
M=(phik*Pxx*phik')+Q;
S=(C*M*C')+R;
K=(M*C')/S;
X2=X1+K*Inno;
Pxy=(eye(2)-K*C)*M;
y=X2;
end

답변 (1개)

Ryan Livingston
Ryan Livingston 2015년 3월 15일
As the error states, the variables X2 and Pxy are undefined before they are used. They need to have definitions, i.e. assignments to them, or be passed as inputs to the MATLAB Function Block in order to be used on the RHS of an assignment.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by