matlab s函数的模板
时间: 2023-11-02 21:27:59 浏览: 131
matlabS-函数的标准模板
function [sys,x0,str,ts] = myfun(t,x,u,flag)
switch flag
case 0 % Initialization
sizes = simsizes; % Get the simulation sizes
sizes.NumContStates = 0; % Number of continuous states
sizes.NumDiscStates = 0; % Number of discrete states
sizes.NumOutputs = 1; % Number of outputs
sizes.NumInputs = 1; % Number of inputs
sizes.DirFeedthrough = 0; % Direct feedthrough flag
sizes.NumSampleTimes = 1; % Number of sample times
sys = simsizes(sizes); % Return simulation sizes
x0 = []; % Initialize the initial states
str = []; % Initialize the state ordering string
ts = [0 0]; % Initialize the sample times
case 1 % Derivatives
sys = [];
case 2 % Discrete states
sys = [];
case 3 % Outputs
sys = u; % Return the output
case 4 % Update
sys = [];
case 9 % Terminate
sys = [];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
end
阅读全文