📄 zhe13.asv
字号:
function [sys,x0,str,ts]=zhe13(t,x,u,flag)
switch flag,
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
%%%%%%%%%%%%%%%
% Derivatives %
%%%%%%%%%%%%%%%
case 1,
sys=[];
%%%%%%%%%%
% Update %
%%%%%%%%%%
case 2,
sys=mdlUpdate(t,x,u);
%%%%%%%%%%%
% Outputs %
%%%%%%%%%%%
case 3,
sys=mdlOutputs(t,x,u);
%%%%%%%%%%%%%%%%%%%%%%%
% GetTimeOfNextVarHit %
%%%%%%%%%%%%%%%%%%%%%%%
case 4,
sys=[];
%%%%%%%%%%%%%
% Terminate %
%%%%%%%%%%%%%
case 9,
sys=mdlTerminate(t,x,u);
%%%%%%%%%%%%%%%%%%%%
% Unexpected flags %
%%%%%%%%%%%%%%%%%%%%
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
% end sfuntmpl
%
%=============================================================================
% 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.
%
% Note that in this example, the values are hard coded. This is not a
% recommended practice as the characteristics of the block are typically
% defined by the S-function parameters.
%
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 3;
sizes.NumOutputs = 1;
sizes.NumInputs = 1;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
%
% initialize the initial conditions
%
x0 = [0 0 0];
%
% str is always an empty matrix
%
str = [];
%
% initialize the array of sample times
%
ts = [0.001 0];
% end mdlInitializeSizes
%
%=============================================================================
% mdlDerivatives
% Return the derivatives for the continuous states.
%=============================================================================
%
function sys=mdlDerivatives(t,x,u)
sys =[];
% end mdlDerivatives
%
%=============================================================================
% mdlUpdate
% Handle discrete state updates, sample time hits, and major time step
% requirements.
%=============================================================================
%
function sys=mdlUpdate(t,x,u)
if u>0
if (u>0)&&(u<=16)
sys=[10000000 0000000 zhuanhuan(abs(u))];
elseif u>16&&u<=32
sys=[10000000 0010000 zhuanhuan(abs(u))];
elseif u>32&&u<=64
sys=[10000000 0100000 zhuanhuan(abs((u-32)/2))];
elseif u>64&&u<=128
sys=[10000000 0110000 zhuanhuan(abs((u-64)/4))];
elseif u>128&&u<=256
sys=[10000000 1000000 zhuanhuan(abs((u-128)/8))];
elseif u>256&&u<=512
sys=[10000000 1010000 zhuanhuan(abs((u-256)/16))];
elseif u>512&&u<=1024x
sys=[10000000 1100000 zhuanhuan(abs((u-512)/32))];
elseif u>1024&&u<=2048
sys=[10000000 1110000 zhuanhuan(abs((u-1024)/64))];
end
else if u<0
if abs(u)>0&&abs(u)<=16
sys=[00000000 0000000 zhuanhuan(abs(u))];
elseif u>16&&u<=32
sys=[00000000 0010000 zhuanhuan(abs(u))];
elseif u>32&&u<=64
sys=[00000000 0100000 zhuanhuan(abs((u-32)/2))];
elseif u>64&&u<=128
sys=[00000000 0110000 zhuanhuan(abs((u-64)/4))];
elseif u>128&&u<=256
sys=[00000000 1000000 zhuanhuan(abs((u-128)/8))];
elseif u>256&&u<=512
sys=[00000000 1010000 zhuanhuan(abs((u-256)/16))];
elseif u>512&&u<=1024x
sys=[00000000 1100000 zhuanhuan(abs((u-512)/32))];
elseif u>1024&&u<=2048
sys=[00000000 1110000 zhuanhuan(abs((u-1024)/64))];
end
end
end
% end mdlUpdate
%
%=============================================================================
% mdlOutputs
% Return the block outputs.
%=============================================================================
%
function sys=mdlOutputs(t,x,u)
sys=x(1)+x(2)+x(3);
% end mdlOutputs
%
%=============================================================================
% mdlGetTimeOfNextVarHit
% Return the time of the next hit for this block. Note that the result is
% absolute time. Note that this function is only used when you specify a
% variable discrete-time sample time [-2 0] in the sample time array in
% mdlInitializeSizes.
%=============================================================================
%
% end mdlGetTimeOfNextVarHit
%
%=============================================================================
% mdlTerminate
% Perform any end of simulation tasks.
%=============================================================================
%
function sys=mdlTerminate(t,x,u)
sys = [];
% end mdlTerminate
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -