0

我在 s-function 中调用一个 m 文件,用于连续状态空间模型。在第 24 行使用带有开关的标志时出错。

function [sys,x0,str,ts] = latitude(t,x,u,flag)
% CSFUNC An example M-file S-function for defining a system of
% continuous state equations:
% x' = Ax + Bu
% y = Cx + Du
%
% Generate a continuous linear system:
A=[0.08774    7.315    81.13    6.589
   0.01938   0.4011    15.58    1.182
   0.0986     2.04    73.46  0.01816
   0        1  -0.1425        0];
B=[  0.5264
     0.1163
     0.5916
     0];
C=[1      0      0      0
   0      1      0      0
   0      0      1      0
   0      0      0      1];
D=[0
   0
   0
   0];
switch flag,
case 0,
[sys,x0,str,ts]=latInitializeSizes(A,B,C,D); % Initialization
case 1,
sys = latDerivatives(t,x,u,A,B,C,D); % Calculate derivatives
case 3,
sys = latOutputs(t,x,u,A,B,C,D); % Calculate outputs
case { 2, 4, 9 } % Unused flags
sys = [];
otherwise
error(['Unhandled flag = ',num2str(flag)]); % Error handling
end

错误是:

"??? 输入参数 "flag" 未定义。==> latitude at 24 switch flag 中的错误,"

主 m 文件的子函数是:

01:

function [sys,x0,str,ts] = latInitializeSizes(A,B,C,D)
%
% Call simsizes for a sizes structure, fill it in and convert it
% to a sizes array.
%
sizes = simsizes;
sizes.NumContStates = 4;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 4;
sizes.NumInputs = 1;
sizes.DirFeedthrough = 0; % Matrix D is nonempty.
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
%
% Initialize the initial conditions.
%
x0 = zeros(4,1);
%
% str is an empty matrix.
%
str = [];
%
% Initialize the array of sample times; in this example the sample
% time is continuous, so set ts to 0 and its offset to 0.
%
ts = [0 0];
end
% End of mdlInitializeSizes.

02:

function sys = latDerivatives(t,x,u,A,B,C,D)
A=[0.08774    7.315    81.13    6.589
   0.01938   0.4011    15.58    1.182
   0.0986     2.04    73.46  0.01816
   0        1  -0.1425        0];
B=[  0.5264
     0.1163
     0.5916
     0];
u=[1];
 x=[0
  0
   0
   0];
sys = A*x + B*u;
end
% End of mdlDerivatives.

03:

function sys = latOutputs(t,x,u,A,B,C,D)

C=[1      0      0      0
   0      1      0      0
   0      0      1      0
   0      0      0      1];
D=[0
   0
   0
   0];
u=[1]; 
x=[0
   0
   0
   0];
sys = C*x + D*u;
end

子功能没有给出任何错误。

4

0 回答 0