📄 sfundsc1.m
字号:
function [sys, x0] = sfundsc1(t,x,u,flag)
%SFUNDSC1 An example S-function for discrete systems with no sample time.
% This M-file is designed to be used as a template for other
% S-functions. Right now it acts as a one integration step "memory"
% block. This template is an example of a discrete system with no
% explicit update time. That is, it makes no use of FLAG==4, so
% the states get updated every time the clock advances (every
% "realtime hit").
%
% Copyright (c) 1990-94 by The MathWorks, Inc.
% Ned Gulley 8-11-92
% Uncomment the following two lines to show how the flags are called.
% dispString=['flag = ' num2str(flag) ' at time = ' num2str(t)];
% disp(dispString)
if abs(flag) == 2,
% The FLAG==2 branch is at the top of the file for efficiency, since
% the S-function will be called with FLAG==2 very frequently.
% If FLAG==2, then SIMULINK is looking for the next point in real time.
% **** In this template system, the current state x gets the input u ****
% (SYS =) XNEW = U
sys = u;
elseif flag == 3,
% If FLAG==3, then SIMULINK wants to know what the next output is.
% **** In this template system, y gets the current state x ****
% (SYS =) Y = X
sys = x;
elseif flag == 0,
% This part takes care of all initialization; it is used only once.
% **** In this template system, there is one discrete state, one ****
% **** input and one output. ****
% The sizes vector is six elements long, and it looks like this:
% sizes(1) = number of continuous states
sizes(1) = 0;
% sizes(2) = number of discrete states
sizes(2) = 1;
% sizes(3) = number of system outputs (length of output y)
sizes(3) = 1;
% sizes(4) = number of system inputs (length of input u)
sizes(4) = 1;
% sizes(5) = number of discontinuous roots; unused feature, set to zero
sizes(5) = 0;
% sizes(6) = direct feedthrough flag; used to detect algebraic loops.
% Set sizes(6) to 1 if the output y depends directly on the input u.
% Otherwise, it should be set to 0.
sizes(6) = 0;
% Set the initial conditions on the states
x0 = 0;
% (SYS =) SIZES = [0 1 1 1 0 0]';
sys = sizes';
else
% Flags not considered here are treated as unimportant.
% Notice that since there are no continuous states in this system,
% there is no need to deal with FLAG==1, and since there is no explicit
% timing associated with this system, there is no need to deal with
% FLAG==4.
% Output is set to [].
sys = [];
end % if abs(flag) == ...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -