Writing S-Functions    
mdlUpdate

Update a block's states.

Syntax

Arguments

S
   SimStruct representing an S-Function block.

tid
   Task ID.

Description

Simulink invokes this optional method at each major simulation time step. The method should compute the S-function's states at the current time step and store the states in the S-function's state vector. The method can also perform any other tasks that the S-function needs to perform at each major time step.

Use this code if your S-function has one or more discrete states or does not have direct feedthrough.

The reason for this is that most S-functions that do not have discrete states but do have direct feedthrough do not have update functions. Therefore, Simulink is able to eliminate the need for the extra call in these circumstances.

If your S-function needs to have its mdlUpdate routine called and it does not satisfy either of the above two conditions, specify that it has a discrete state, using the ssSetNumDiscStates macro in the mdlInitializeSizes function.

The tid (task ID) argument specifies the task running when the mdlOutputs routine is invoked. You can use this argument in the mdlUpdate routine of a multirate S-Function block to encapsulate task-specific blocks of code (see Multirate S-Function Blocks).

Example

For an example, see matlabroot/simulink/src/dsfunc.c.

Languages

Ada, C, M

See Also

mdlDerivatives, ssGetContStates, ssGetDiscStates


  mdlTerminate mdlZeroCrossings