Skip to Main Content Skip to Search
Product Documentation

mdlSetWorkWidths - Specify the sizes of the work vectors and create the run-time parameters required by this S-function

Required

No

C Syntax

#define MDL_SET_WORK_WIDTHS
void mdlSetWorkWidths(SimStruct *S)

C Arguments

S

SimStruct representing an S-Function block.

MATLAB Syntax

PostPropagationSetup(s)

MATLAB Arguments

s

Instance of Simulink.MSFcnRunTimeBlock class representing the Level-2 MATLAB S-Function block.

Description

The Simulink engine calls this optional method to enable this S-function to set the sizes of state and work vectors that it needs to store global data and to create run-time parameters (see Run-Time Parameters). The engine invokes this method after it has determined the input port width, output port width, and sample times of the S-function. This allows the S-function to size the state and work vectors based on the number and sizes of inputs and outputs and/or the number of sample times. This method specifies the state and work vector sizes via the macros ssGetNumContStates, ssSetNumDiscStates, ssSetNumRWork, ssSetNumIWork, ssSetNumPWork, ssSetNumModes, and ssSetNumNonsampledZCs.

A C-MEX S-function needs to implement this method only if it does not know the sizes of all the work vectors it requires when the engine invokes the function's mdlInitializeSizes method. If this S-function implements mdlSetWorkWidths, it should initialize the sizes of any work vectors that it needs to DYNAMICALLY_SIZED in mdlInitializeSizes, even for those whose exact size it knows at that point. The S-function should then specify the actual size in mdlSetWorkWidths. This method is only valid for simulation, and must be enclosed in a #if defined(MATLAB_MEX_FILE) statement.

A Level-2 MATLAB S-function must implement this method if any DWork vectors are used in the S-function. In the case of MATLAB S-functions, this method sets the number of DWork vectors and initializes their attributes. For example, the following code in the PostPropagationSetup method specifies the usage for the first DWork vector:

s.DWork(1).Usage = type;

where s is an instance of the Simulink.MSFcnRunTimeBlock class representing the Level-2 MATLAB S-Function block and type is one of the following:

C Example

For a full example of a C MEX S-function using DWork vectors, see the file sfun_rtwdwork.c used in the Simulink model sfcndemo_sfun_rtwdwork.mdl.

MATLAB Example

For a full example of a Level-2 MATLAB S-function using DWork vectors, see the file adapt_lms.m used in the Simulink model sldemo_msfcn_lms.mdl.

Languages

C, C++, MATLAB

See Also

mdlInitializeSizes

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS