⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cnf_disturbance.m

📁 hard disk drive servo control tools, it is very helpful
💻 M
字号:
function [sys,x0,str,ts] = cnf_disturbance(t,x,u,flag,p1)
% This S function produce a vector output based on the expression of p1. 
% It is called from the Simulink model cnf_sim.mdl
% The general structure of an S-function is used

switch flag,
case 0, % Initialization %
    [sys,x0,str,ts]=mdlInitializeSizes(t,x,u,p1);
case 1,% Derivatives %
    % Do nothing not used    
    % sys=mdlDerivatives(t,x,u);
case 2,  % Update %
%     [sys] = mdlUpdate(t,x,u,p1);
      sys=[];   
case 3,  % Outputs %
    sys=mdlOutputs(t,x,u,p1);
case 4,  % GetTimeOfNextVarHit %
    % Do nothing not used
    % sys=mdlGetTimeOfNextVarHit(t,x,u);
case 9,  % Terminate %
    sys=mdlTerminate(t,x,u);
otherwise  % Unexpected flags %
    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(t,x,u,p1)
% 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.
u=1;
the_w=eval(p1);

sizes = simsizes;
sizes.NumContStates  = 0;
sizes.NumDiscStates  = 0;
sizes.NumOutputs     = length(the_w);
sizes.NumInputs      = 1;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;   % at least one sample time is needed
sys = simsizes(sizes);
% initialize the initial conditions
x0  = [];
% str is always an empty matrix
str = [];
% initialize the array of sample times
ts  = [0 0];
% end mdlInitializeSizes

%=============================================================================
% mdlOutputs     flag = 3
%=============================================================================
function sys=mdlOutputs(t,x,u,p1)
u=t;
sys = eval(p1);
% end mdlOutputs


%=============================================================================
% mdlTerminate    flag = 9
% 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 + -