Main Content

Receive or Output Function-Call Signals for Simulation and Code Generation

This example shows how the Variant Source block allows function-call signals to be merged.

Explore the Model

Open the model slexVariantSourceFunctionCall.slx. The model contains a Variant Source block with the conditions A==1 and A==2 at its input ports. A is the variant control variable defined in the PostLoadFcn in File > ModelProperties > Callbacks. The variant conditions at the inports and outports of the Variant Source block determine the activation and deactivation of the blocks connected to it.

A Sine Wave block is connected to two MATLAB® function-call blocks. The function-call block named Filter Positive input is triggered when the Sine Wave value block is positive. The function-call block named Filter Negative input is triggered when the Sine Wave block value is 0 or negative. The output port of the Variant Source block is connected to function-call subsystem called counter. The subsystem is triggered when A==1 and the Sine Wave block outputs positive values, and when A==2 and the Sine Wave block outputs negative values.

open_system('slexVariantSourceFunctionCall.slx')

Simulate the Model

1 Enable the Output function call option on the Variant Source Block Parameters dialog box. To enable this option programmatically, use this command:

set_param(slexVariantSourceFunctionCall/Variant Source,'OutputFunctionCall','On')

2 Simulate the model by executing Simulation > Update Diagram.The variant condition propagation determines active and inactive variant choices.

  • When A==1 and the Sine Wave block output is positive, the function-call block named Filter Positive input is active.

  • When A==2 and the Sine Wave block utput is equal to 0 or negative, the function-call block named Filter Negative input is active.

In both cases, the count value in the function-call subsytem named Counter is incremented. If A~=1 and A~=2, then 'Counter' does not execute, as the Sine Wave block is inactive.

sim('slexVariantSourceFunctionCall.slx')
load_system('slexVariantSourceFunctionCall/Counter')