User`s guide

2 Writing S-Functions As M-Files
2-18
function [sys,x0,str,ts] = vsfunc(t,x,u,flag)
% This example S-function illustrates how to create a variable
% step block in Simulink. This block implements a variable step
% delay in which the first input is delayed by an amount of time
% determined by the second input:
%
% dt = u(2)
% y(t+dt) = u(t)
%
switch flag,
case 0
[sys,x0,str,ts] = mdlInitializeSizes; % Initialization
case 2
sys = mdlUpdate(t,x,u); % Update Discrete states
case 3
sys = mdlOutputs(t,x,u); % Calculate outputs
case 4
sys = mdlGetTimeOfNextVarHit(t,x,u); % Get next sample time
case { 1, 9 }
sys = []; % Unused flags
otherwise
error(['Unhandled flag = ',num2str(flag)]); % Error handling
end
% End of vsfunc.
%==============================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the
% S-function.
%==============================================================
%
function [sys,x0,str,ts] = mdlInitializeSizes
%
% Call simsizes for a sizes structure, fill it in and convert it
% to a sizes array.
%