Reuse Multiple Instances of a Simulink Function - MATLAB & Simulink (original) (raw)
Main Content
This example shows how to reuse instances of the same Simulink® function. The model slexCounterFunctionMdlRef
contains the update
function, which implements a counter. Subsystems CounterA
and CounterB
each contain an instance of the counter, allowing the model to reuse the function logic.
Open the model.
open_system('slexMultiInstanceFunctionsExample');
Implement Reusable Simulink Function
The function in the slexMultiInstanceFunctionsExample
model is the update
function which is defined in the slexCounterFunctionMdlRef
subsystem.
To view the Simulink Function block, open the CounterA
subsystem.
open_system('slexMultiInstanceFunctionsExample/CounterA');
Subsystems CounterA
and CounterB
each contain an instance of the counter implemented in the slexCounterFunctionMdlRef
model. Since there are multiple instances of the counter, the model can reuse the function logic and can call each instance from multiple blocks.
Call Same Simulink Function from Separate Callers
The function callers in the slexMultiInstanceFunctionsExample
model are in the UpdateCounterA
and UpdateCounterB
subsystems. The calling notation CounterA.update
and CounterB.update
distinguishes the two different instances of the counter logic.
To view the callers for CounterA
, double-click the UpdateCounterA
subsystem. The Function Caller blocks in the subsystem qualify the function name with the Model block name. In this case, CounterA
is the Model block name and update
is the function name.
sim('slexMultiInstanceFunctionsExample');
See Also
Argument Inport | Argument Outport | Function Caller | Model | Simulink Function