Conditionally Execute Referenced Models - MATLAB & Simulink (original) (raw)
Main Content
A conditionally executed referenced model, or_conditional model_, allows you to control its execution with an external signal. The external signal, called the control signal, is attached to the control input port. Conditional models are useful when you create complex model hierarchies that contain components whose execution depends on other components.
Conditional Models
You can set up referenced models to execute conditionally, similar to conditional subsystems. For information about conditional subsystems, see Conditionally Executed Subsystems Overview.
Simulink® software supports these conditional model types:
Conditional Model | Description |
---|---|
Enabled | An enable port executes a referenced model at each simulation step for which the control signal has a positive value. To add an enable port to aModel block, insert an Enable block in the referenced model.![]() |
Triggered | A trigger port executes a referenced model each time a trigger event occurs. To add a trigger port to a Model block, insert a Trigger block in the referenced model.![]() |
Triggered and Enabled | A Model block can have both trigger and enable ports. If the enable control signal has a positive value at the time step for which a trigger event occurs, a triggered and enabled model executes once. |
Function-Call | A function-call port executes a referenced model each time a function-call event occurs. To add a function-call port to a Model block, insert a Trigger block in the referenced model. Then, open the Block Parameters dialog box and set the Trigger type tofunction-call.A Stateflow® chart, a Function-Call Generator block, a Hit Crossing block, or an appropriately configured custom S-function can provide function-call events. See Using Function-Call Subsystems.![]() |
Requirements for Conditional Models
Conditional models must meet the requirements for:
- Conditional subsystems (see Conditionally Executed Subsystems and Models)
- Referenced models (see Reference Existing Models)
Conditional models must also meet the requirements specific to each type of conditional model.
Conditional Model | Requirements |
---|---|
Enabled | Multi-rate enabled models cannot use multi-tasking solvers. Use single-tasking.For models with enable ports at the root, if the model uses a fixed-step solver, the fixed-step size of the model must not exceed the rate for any block in the model.Signal attributes of the enable port in the referenced model must be consistent with the input that the Model block provides to that enable port. |
Triggered | Signal attributes of the trigger port in the referenced model must be consistent with the input that the Model block provides to that trigger port. |
Triggered and Enabled | See requirements for triggered models and enabled models. |
Function-Call | A function-call model cannot have an output port driven only byGround blocks, including hiddenGround blocks inserted by Simulink. To meet this requirement:Insert a Signal Conversion block into the signal connected to the output port.Enable the Exclude this block from 'Block reduction' optimization option of the inserted block.The parent model must trigger the function-call model at the rate specified by the > 'Fixed-step size' option if the function-call model meets both these conditions:It specifies a fixed-step solver.It contains one or more blocks that use absolute or elapsed time.Otherwise, the parent model can trigger the function-call model at any rate.A function-call model must not have direct internal connections between its root-level input and output ports.If the Sample time type isperiodic, the sample-time period must not contain an offset.The signal connected to a function-call port of aModel block must be scalar. |
Modify a Referenced Model for Conditional Execution
- At the root level of the referenced model, insert one of these blocks.
Type of Model Blocks to Insert Enabled Enable Triggered Trigger Triggered and Enabled Trigger and Enable Function-Call Trigger For an enabled model, go to Step 3. - For the Trigger block, set the Trigger type parameter value.
Model Type Trigger Type TriggeredTriggered and enabled Choose one of these values:risingfallingeither Function-call function-call - Use the Model block ports to connect the referenced model to other ports in the parent model.
- The top of the Model block displays an icon that corresponds to the control signal type expected by the referenced model. For a triggered model, the top of the Model block displays this icon.
- The top of the Model block displays an icon that corresponds to the control signal type expected by the referenced model. For a triggered model, the top of the Model block displays this icon.
See Also
Enable | Trigger | Function-Call Subsystem