www.gusucode.com > MATLAB雷达工具箱 > MATLAB雷达工具箱/MATLAB雷达工具箱/dbtlinkR1-3/fromfile_s.m

    function [sys,x0,str,ts] = fromfile_s(t,x,u,flag,fileName,varName)
%
%   The general form of an M-File S-function syntax is:
%       [SYS,X0,STR,TS] = SFUNC(T,X,U,FLAG,P1,...,Pn)
%
%   Optional parameters, P1,...,Pn can be provided to the S-function and
%   used during any FLAG operation.

switch flag,

  case 0,
    [sys,x0,str,ts]=mdlInitializeSizes;

  case { 1, 2, 4, 9 }
    sys=[];		% Unused flags

  case 3,
    sys=mdlOutputs(t,x,u,fileName,varName);

  otherwise
    error(['Unhandled flag = ',num2str(flag)]);

end

%
%=============================================================================
% 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.

sizes = simsizes;

sizes.NumContStates  = 0;
sizes.NumDiscStates  = 0;
sizes.NumOutputs     = 1;
sizes.NumInputs      = 0;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;   % at least one sample time is needed

sys = simsizes(sizes);

x0  = [];		% No continuous states
str = []; 	% str is always an empty matrix, reserved for future use by Simulink
ts  = [0 0];	% initialize the array of sample times

% end mdlInitializeSizes

%=============================================================================
% mdlOutputs
% Return the block outputs.
%=============================================================================
function sys=mdlOutputs(t,x,u,fileName,varName)

  % The parameters fileName and varName contains the desired file and variable names.
  eval(['clear ',varName])
  eval(['load ',fileName])
  
  paramNoOut1 = getparamno;
  eval(['global pipeVar',num2str(paramNoOut1)])
  eval(['pipeVar',num2str(paramNoOut1),' = ',varName,';'])
  eval(['clear ',varName])

  sys = paramNoOut1;
% end mdlOutputs