首页 > > 详细

讲解留学生Matlab编程、Statistics统计解析、辅导Matlab语言、Matlab调试

function [sys,x0,str,ts] = ilc_memory_position(t,x,u,flag)
% Dispatch the flag. The switch function controls the calls to
% S-function routines at each simulation stage.
number=1000;
switch flag,
case 0
[sys,x0,str,ts] = mdlInitializeSizes(number); % Initialization
case 2
sys=mdlUpdate(t,x,u,number);
case 3
sys = mdlOutputs(t,x,u); % Calculate outputs
case {1, 4, 9 }
sys = []; % Unused flags
otherwise
error(['Unhandled flag = ',num2str(flag)]); % Error handling
end; % End of function timestwo.%==============================================================
% Function mdlInitializeSizes initializes the states, sample
% times, state ordering strings (str), and sizes structure.
%==============================================================
function [sys,x0,str,ts] = mdlInitializeSizes(number)
% Call function simsizes to create the sizes structure.
sizes = simsizes;
% Load the sizes structure with the initialization information.
sizes.NumContStates= 0;
sizes.NumDiscStates= number+1;
sizes.NumOutputs= 1;
sizes.NumInputs= 2;
sizes.DirFeedthrough=1;
sizes.NumSampleTimes=1;
% Load the sys vector with the sizes information.
sys = simsizes(sizes);
%
%x0=[0,0,0,0,0,0,0,0,0,0];
xx(1:number+1)=0;
x0=xx';
%
str = []; % No state ordering
%
ts = [0 0]; % Inherited sample time
% End of mdlInitializeSizes.
%==============================================================
% Function mdlOutputs performs the calculations.
%==============================================================
function sys=mdlUpdate(t,x,u,number)
if(u(2)-x(number+1)>=1)
x(number+1)=u(2);
y=x(2:number);
x=[y;u(1);x(number+1)];
end
sys=x;
function sys = mdlOutputs(t,x,u)
sys = [x(1)];
% End of mdlOutputs.
%A=[1,0;0,1];B=[2,0;0,2];
 

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!