No BSD License  

Highlights from
Examples of incorporating m-code into Simulink models

Examples of incorporating m-code into Simulink models

by

 

23 Sep 2004 (Updated )

Example Simulink models to support a MATLAB Digest article from September 2004.

eqn_L2_sfcn(block)
function eqn_L2_sfcn(block)
% Level-2 M file S-Function for times two demo.
%   Copyright 1990-2004 The MathWorks, Inc.
%   $Revision: 1.1.4.1 $ 

  setup(block);
  
%endfunction

function setup(block)
  
  %% Register number of input and output ports
  block.NumInputPorts  = 2;
  block.NumOutputPorts = 1;

  %% Setup functional port properties to dynamically
  %% inherited.
  block.SetPreCompInpPortInfoToDynamic;
  block.SetPreCompOutPortInfoToDynamic;
 
  block.InputPort(1).DirectFeedthrough = true;
  
  %% Set block sample time to inherited
  block.SampleTimes = [-1 0];
  
  %% Run accelerator on TLC
  block.SetAccelRunOnTLC(true);
  
  %% Register methods
  block.RegBlockMethod('Outputs',                 @Output);  
  
%endfunction

function Output(block)

  block.OutputPort(1).Data = -0.366 + ...
      0.08979*block.InputPort(1).Data*block.InputPort(2).Data ...
      - 0.0337*block.InputPort(2).Data*block.InputPort(1).Data.^2 ...
      + 0.0001*block.InputPort(1).Data*block.InputPort(2).Data.^2;
  
%endfunction

Contact us