A Function-Call Subsystem block is a conditionally executed subsystem that runs each time the control port receives a function-call event. A Stateflow® chart, Function-Call Generator block, MATLAB Function block, S-Function block, or Hit Crossing block can provide function-call events.
A function-call subsystem is analogous to a function in a procedural programming language. Invoking a function-call subsystem executes the output methods of the blocks within the subsystem in execution order. For an explanation of the Function-Call Subsystem block parameters, see Subsystem.
To create a function-call subsystem:
Add a Function-Call Subsystem block to your model.
Open the subsystem block. Add a block diagram defining the algorithm that is executed when the subsystem receives a function-call event.
Set how subsystem states are handled when the subsystem is executed:
Open the subsystem block, then open the block parameters dialog box for the Trigger block. From the States when enabling drop-down list, select an option:
held — States maintain their most recent
reset — States set to their initial
inherit — Use the held or reset setting from
the parent subsystem initiating the function-call.
For nested subsystems whose Function-Call Subsystem blocks have different parameter settings, the settings for the child subsystem override the settings inherited from the parent subsystem. See Trigger.
Attach a function-call initiator to the function-call input port.
If you attach an Inport block, open the block, select the Signal Attributes tab, then select the Output function call check box.
Configure a Function-Call Subsystem block by setting the Sample
time type of its Trigger Port block to
A triggered (aperiodic) function-call subsystem can execute zero, one, or multiple times during a time step.
If a function-call subsystem is executed by a root-level function-call
Inport block with a discrete sample time, multiple function-calls
during a time step are not allowed. To allow multiple function-calls, set
Sample time to
-1 (inherited), and set the
sample time for all blocks in the function-call subsystem to
A periodic function-call subsystem executes once during each time step when it
receives a function-call signal, and does not execute at a time step when it does not
receive a function-call signal. Set the sample time for all blocks in the function-call
During range checking, the minimum and maximum parameter settings are back-propagated to the actual source port of the function-call subsystem, even when the function-call subsystem is not enabled.
To prevent this back propagation:
Add a Signal Conversion block and a Signal Specification block after the source port.
Set the Output of the Signal Conversion block
Specify the minimum and maximum values for the Signal Specification block instead of specifying them on the source port.