Main Content

Model

Reference another model to create model hierarchy

  • Library:
  • Simulink / Ports & Subsystems

    HDL Coder / Ports & Subsystems

  • Model block

Description

TheModelblock references the specified model. It displays input and output ports that correspond to the top-level input and output ports of the referenced model. These ports allow you to connect the referenced model to other blocks in the parent model.

To determine whether theModelblock is better suited for your goal than another block with similar functionality, seeChoose Among Types of Model ComponentsandCompare Capabilities of Model Components.

For instructions on how to reference a model with aModelblock, seeReference Existing Models.

By default, theModelblock displays a representation of the contents of the referenced model. For more information, see预览内容的模型组件. To see the contents of a referenced model, double-click theModelblock.

If you have a金宝app®Coder™license, you can conceal the implementation details of a referenced model by protecting the model. To protect a model, seeProtect Models to Conceal Contents(Simulink Coder). To reference a protected model, seeReference Protected Models from Third Parties.

Ports

Input

expand all

TheModelblock has an input port for each input port of the model it references. The input ports of referenced models are defined byInportandIn Bus Elementblocks. The name of theModelblock port matches the name of the corresponding port in the referenced model. The input signal for eachModelblock port must be valid for the corresponding port in the referenced model. For more information, seeModel Reference Interface and Boundary.

Function calls connected to an input port pass into the referenced model. To conditionally execute the referenced model based on a function call, seeFunction Call.

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64|Boolean|fixed point|enumerated|bus
Complex Number Support:Yes

Output

expand all

TheModelblock has an output port for each output port of the model it references. The output ports of referenced models are defined byOutportandOut Bus Elementblocks. The name of the port on theModelblock matches the name of the corresponding port in the referenced model. The output signals of theModelblock are the signals connected to theOutportandOut Bus Elementblocks in the referenced model. SeeModel Reference Interface and Boundary.

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64|Boolean|fixed point|enumerated|bus
Complex Number Support:Yes

Control

expand all

Conditional Execution

The enable port appears at the top of theModelblock. The port label is an icon that represents an enable signal.

Enable port on Model block

The control signal that connects to the port determines when to execute the referenced model. For more information, seeConditionally Execute Referenced Models.

Dependencies

To enable this port, add anEnable块顶级的参考模型。

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64|Boolean|fixed point

The trigger port appears at the top of theModelblock. The port label is an icon that represents a trigger signal.

Trigger port on Model block

The control signal that connects to the port determines when to execute the referenced model. For more information, seeConditionally Execute Referenced Models.

Dependencies

To enable this port, add aTriggerblock to the top level of the referenced model and set itsTrigger typetorising,falling, oreither.

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64|Boolean|fixed point

The function-call port appears at the top of theModelblock. The port label displays the name of the referenced model as a function.

Function-call port on Model block

The control signal that connects to the port determines when to execute the referenced model. For more information, seeConditionally Execute Referenced Models.

Dependencies

To enable this port, add aTriggerblock to the top level of the referenced model and set itsTrigger typetofunction-call.

Model Events Simulation

The initialize event port provides a control signal that triggers a model initialize event, which initializes the states of the referenced model.

The referenced model can contain anInitialize Functionblock that corresponds to the model initialize event. For more information, see使用初始化、复位和终止功能.

Dependencies

To enable this port, selectShow model initialize port.

A reset event port provides a control signal that triggers a model reset event, which resets the states of the referenced model.

必须包含一个引用的模型Reset Functionblock that corresponds to each model reset event. For more information, see使用初始化、复位和终止功能.

To specify the port name, use theEvent nameparameter of theEvent Listenerblock in theReset Functionblock.

Dependencies

To enable this type of port, selectShow model reset ports.

The terminate event port provides a control signal that triggers a model terminate event, which reads and saves the states of the referenced model.

The referenced model can contain aTerminate Functionblock that corresponds to the model terminate event. For more information, see使用初始化、复位和终止功能.

Dependencies

To enable this port, selectShow model terminate port.

Periodic event ports provide control signals that specify when to execute the model. For an example, seeTest Rate-Based Model Simulation Using Function-Call Generators.

Each port label displays information about the periodic event, such as the sample time of the correspondingInportblock. For example, theModelblock in this image displays periodic event ports and references a model with two discrete rates: 0.01 and 0.1.

A Model block has ports labeled D1[0.01] and D2[0.1].

Dependencies

To enable this type of port, setSchedule rates withtoPorts.

Parameters

expand all

To interactively modifyModelblock parameters, select theModelblock. Then, in the Simulink Toolstrip, on theModel Blocktab, clickBlock Parameters.

Main

Specify fundamental information for theModelblock.

Specify the file name of the referenced model. The file name must be a valid MATLAB®identifier for a model, as defined inModel Names. The file extension is optional.

To select the model that you want to reference, clickBrowse. To view the specified model, clickOpen Model.

Programmatic Use

You can query the name of the referenced model in different formats:

  • ModelFile— Model name with file extension. When you do not specify a file extension, the first match that Simulink finds on the MATLAB path determines the file extension.

  • ModelNameDialog— Model name with or without file extension, depending on whether you specify a file extension.

  • ModelName— Model name without file extension. If you specify a model name with a file extension forModelName, Simulink retains the file extension by settingModelNameDialogandModelFile.

Parameter:ModelNameDialog
Type: character vector
Value:|''
Default:

Specify the simulation mode for theModelblock. The simulation mode for theModelblock can be different than the simulation mode of its referenced model and of other models in the model hierarchy.

  • Accelerator— Create a MEX file for the referenced model and then execute the referenced model by running the S-function.

  • Normal— Execute the referenced model interpretively, as if the referenced model is an atomic subsystem implemented directly within the parent model.

  • Software-in-the-loop (SIL)— This option requires an Embedded Coder®license. Generate production code based on theCode interfaceparameter setting. The code is compiled for and executed on the host platform.

  • Processor-in-the-loop (PIL)— This option requires an Embedded Coder license. Generate production code based on theCode Interfaceparameter setting. This code is compiled for and executed on the target platform. A target connectivity API implementation supports the exchange of data between the host and target at each time step during the PIL simulation.

The corners of theModelblock indicate the simulation mode of theModelblock. For normal mode, the corners have empty triangles. For accelerator mode, the corner triangles are filled in. For SIL and PIL modes, the corners are filled in and the word(SIL)or(PIL)appears on the block icon.

Although you can specify any simulation mode for a model, when you reference that model, theModelblock specifies the simulation mode of the referenced model instance. The simulation mode of a parent model can override the simulation mode of aModelblock.

For more information, seeChoose Simulation Modes for Model Hierarchies.

Programmatic Use

Parameter:SimulationMode
Type: character vector
Value:'Normal'|'Accelerator'|'Software-in-the-loop'|'Processor-in-the-loop'
Default:'Normal'

Specify whether to generate the code from the top model or the referenced model for SIL and PIL simulation modes. To deploy the generated code as part of a larger application that uses the referenced model, specifyModel reference. To deploy the generated code as a standalone application, specifyTop model.

  • Model reference— The code is generated from the referenced model as part of a model hierarchy. Code generation uses theslbuild('model', 'ModelReferenceCoderTarget')command.

  • Top model— The code is generated from the top model with the standalone code interface. Code generation uses theslbuild('model')command.

Dependencies

To enable this parameter, setSimulation modeto eitherSoftware-in-the-loop (SIL)orProcessor-in-the-loop (PIL).

Programmatic Use

Parameter:CodeInterface
Type:character vector
Value:'Model reference'|'Top model'
Default:'Model reference'

Model Events Simulation

Control when the referenced model executes and changes states.

Select this parameter to display the initialize event port. Clear this parameter to remove the port.

Dependencies

To enable this parameter, reference a model that is not configured for conditional execution.

Programmatic Use

Block parameter:ShowModelInitializePort
Type:character vector
Value:'off'|'on'
Default:'off'

Select this parameter to display the reset event ports. Clear this parameter to remove the ports.

Dependencies

To enable this parameter, reference a model that is not configured for conditional execution and contains aReset Functionblock.

Programmatic Use

Block parameter:ShowModelResetPorts
Type:character vector
Value:'off'|'on'
Default:'off'

Select this parameter to display the terminate event port. Clear this parameter to remove the port.

Dependencies

To enable this parameter, reference a model that is not configured for conditional execution. Then, selectShow model initialize port.

Programmatic Use

Block parameter:ShowModelTerminatePort
Type:character vector
Value:'off'|'on'
Default:'off'

Control the execution of the referenced model with periodic events.

Depending on the value of theSchedule rates withparameter, selecting this parameter will either display the periodic event ports on theModelblock or create partitions to use with theSchedule Editor. When theSchedule rates withparameter is not visible, its default value (Ports) applies.

Clearing this parameter hides the periodic event ports and does not create partitions.

Dependencies

To enable this parameter, reference a model with discrete sample times that is not configured for conditional execution and is not an export-function model. When the parent model is rate based and the referenced model is an export-function model,Schedule ratesis automatically selected.

Programmatic Use

Block parameter:ScheduleRates
Type:character vector
Value:'off'|'on'
Default:'off'

Create ports or partitions.

  • Ports— Display periodic event ports for discrete rates in the referenced model.

    To manually specify port rates, use theset_paramfunction to set theAutoFillPortDiscreteRatesparameter of theModelblock to'off'. Then, specify the port rates with thePortDiscreteRatesparameter.

  • Schedule Editor— Create partitions for the referenced model to use with theSchedule Editor.

Dependencies

To enable this parameter:

  • The parent model must not be an export-function model.

  • The parent model must not use a fixed-step solver and single-tasking mode.

  • SelectSchedule rates. When the parent model is rate based and the referenced model is an export-function model,Schedule ratesis automatically selected.

  • ClearShow model initialize portandShow model reset ports.

Programmatic Use

Block parameter:ScheduleRatesWith
Type:character vector
Value:'Ports'|'ScheduleEditor'
Default:'Ports'

Instance Parameters

Specify instance-specific values for model arguments.

Display instance parameters and specify instance-specific values.Instance parameters块参数的配置the referenced model to use a different value for each instance of the model.

To specify instance-specific values, use theValuecolumn in the table. To specify that a parameter value can be overridden by the parent model, select theArgumentcheck box. For more information about configuring instance parameters in a referenced model and specifying instance-specific values at theModelblock, seeParameterize Instances of a Reusable Referenced Model.

When changing instance-specific values, you can use a partial structure that has fields that correspond to only the instance parameters whose values you want to change. Instance parameters not included in the partial structure retain their values. In the structure, include the instance parameter names and values, specified as character vectors.

Programmatic Use

Block parameter:ParameterArgumentValues
Type:structure
Value:structure
Default:structure with no fields
Block parameter:InstanceParameters
Type:structure array
Value:structure with fields:Name,Value,Path, andArgument.

Block Characteristics

Data Types

Boolean[a]|bus[a]|double[a]|enumerated[a]|fixed point[a]|half[a]|integer[a]|single[a]|string[a]

Direct Feedthrough

no

Multidimensional Signals

limited[a]

Variable-Size Signals

limited[a]

Zero-Crossing Detection

no

[a]Actual data type or capability support depends on block implementation.

Tips

To programmatically determine whether aModelblock references a protected model, use theget_paramfunction to query the read-onlyProtectedModelparameter of theModelblock. If the referenced model is protected, the function returns'on'. If the referenced model is unprotected, the function returns'off'.

Compatibility Considerations

expand all

Warns starting in R2019a

Extended Capabilities

Introduced before R2006a