As a model increases in size and complexity, you can simplify it by grouping blocks into subsystems. A subsystem is a set of blocks that you group into a singleSubsystem堵塞。
Using subsystems:
Establishes a hierarchical block diagram where aSubsystemblock is on one layer and the blocks that make up the subsystem are on another.
Keeps functionally related blocks together.
Helps reduce the number of blocks displayed in your model window.
Establishes an interface with inputs and outputs.
When you make a copy of a subsystem, that copy is independent of the source subsystem. To reuse the contents of a subsystem across a model or across models, consider referenced subsystems, referenced models, or subsystems linked to a block in a custom library. For more information, seeChoose Among Types of Model Components。
A subsystem can be virtual or nonvirtual. Avirtual subsystemprovides graphical hierarchy in a model and does not impact the execution of a model. Anonvirtual subsystemexecutes as a single unit within a model.
Tip
对于控制器和其他独立组件,通过使用非虚拟子系统或引用模型来定义相关块周围的硬边界。定义硬边界的前期会避免在要为组件生成代码时昂贵的重构。
金宝app®classifies nonvirtual subsystems into these types:
Type of Subsystem | Description |
---|---|
Atomic Subsystem | Subsystem that executes as a single unit. |
启用子系统 | 该子系统的执行是由外部输入启用的。 |
Triggered Subsystem | Subsystem whose execution is triggered by external input. |
Function-Call Subsystem | Subsystem whose execution is controlled by an external function-call input. |
Enabled and Triggered Subsystem | Subsystem whose execution is enabled and triggered by external inputs. |
重置table Subsystem | Subsystem whose block states reset with an external trigger. |
If Action Subsystem | Subsystem whose execution is enabled by anIf堵塞。 |
Switch Case Action Subsystem | Subsystem whose execution is controlled by aSwitch Case堵塞。 |
While Iterator Subsystem | 在逻辑条件为真时,在模拟时间步长中重复执行的子系统。 |
对于迭代子系统 | Subsystem that repeats execution during a simulation time step for a specified number of iterations. |
For Each Subsystem | Subsystem that repeats execution on each element or subarray of input signal and concatenates results. |
To create a subsystem, you can:
在Simuli金宝appnk编辑器中,双击并开始键入子系统类型,然后从菜单中选择相应的块。
In the Simulink Editor, drag a selection box to outline the subsystem that you want to create, then select the subsystem type.
Drag aSubsystem距离库浏览器块。
Copy and paste aSubsystem距离模型。
When you create a subsystem from a selection box, the selection can be empty or can contain multiple blocks in one area of the model.
From the action bar, select the type of subsystem that you want to create.
When the selection contains blocks that correspond to input and output ports, the new subsystem includes copies of those blocks. The new subsystem does not contain copies of blocks that correspond to control ports.
你可以改变创造出来后子系统的类型n.
To make a subsystem execute as a unit, click theSubsystem堵塞。在Subsystemtab, selectIs Atomic Subsystem。
要使子系统有条件执行,请添加与控制端口相对应的块。
To make a subsystem execute unconditionally, remove blocks that correspond to control ports.
The ports on aSubsystemblock correspond to blocks inside the subsystem.
For example, thisSubsystemblock has two input ports and one output port.
子系统包含两个Inport块,In1
和In2
, and one外港block,Out1
, that correspond to the ports on theSubsystem堵塞。
To automatically add ports to aSubsystemblock:
Click the edge of theSubsystemblock, then select the type of port to create.
将一条线拖到Subsystem堵塞。
The corresponding port blocks are added inside the subsystem.
Tip
自动端口创建后,端口标签Subsystemblock is enabled for quick editing. See,在子系统上编辑端口标签。
要手动添加端口,请双击该子系统Subsystemblock, then add the corresponding blocks to the subsystem.
端口类型 | Corresponding Block |
---|---|
信号端口,输入 | Inportblock |
Signal port, output | 外港block |
公交端口,输入 | In Bus Elementblock |
Bus port, output | Out Bus Elementblock |
Control port, enabled | Enableblock |
Control port, triggered | Triggerblock |
Control port, function-call | Triggerblock withTrigger typeset tofunction-call |
Control port, reset | 重置block |
Control port, action | Action Portblock |
Connection port | Connection Port(Simscape)block |
更改端口的位置Subsystemblock, drag the port to a new location on any side of theSubsystem堵塞。
By default, Simulink labels the ports on aSubsystem堵塞。To specify how Simulink labels the ports of a subsystem:
Select theSubsystem堵塞。
在格式tab of the Simulink Toolstrip, select one of the labeling options from the端口标签menu. For more information, seeShow port labels。
您可以直接在这些类型的子系统块上编辑端口标签:
常规子系统
Subsystem with mask
变体子系统
Chart subsystem
To edit the port label on a subsystem block in the current model:
Point to the port label. An interactiveport label cue(端口标签周围的蓝色框)出现。单击提示。
Alternatively, select the port and pressF2。提示进入编辑模式。
Creating a new port on aSubsystemblock using automatic port creation also enables the port label cue for quick editing.
A端口选择器提示appears above the port label cue to indicate the port label information (port block name, signal name, bus port, or connection port) that is being edited. For signal ports, you can edit both the port block name and the port signal name from the port label. To switch between the values, click the respective icon in the selector cue or use the keyboard shortcutsCtrl+1,2。
Enter a value in the port label cue and pressEnter或者Esc, or click away.
After the port label is edited, Simulink automatically updates the name of the related port or signal within the subsystem.
Tip
To make successive port label edits on a subsystem block:
Select a port on the block.
编辑端口标签并按Enter。This action enables keyboard selection of ports.
You can select adjacent ports using the up arrow or down arrow key and pressingF2for quick editing.
This table lists the update action depending on the type of port label defined on the subsystem block.
Type of port label | Action |
---|---|
None | Editing not supported. |
Port icon | 根据子系统中的元素名称的更新Icon display端口的参数。 例如,如果的价值Icon displayparameter of the port is Note For this type of port label, the information shown on the port label after an edit depends on the final edit performed on the label using the selector cue:
|
Port block name | Updates the block name of the port in the subsystem. For this type of port label, you can edit only the port block name using the port selector cue. |
Signal name | 更新链接到端口的信号的名称。 |
Note
Simulink does not show the port selector cue forChart块。
Editing port labels onSubsystemblocks with a mask icon is not supported.
Editing port numbers from the port label is not supported. You can still edit the port block name and signal name using the port label cue.
Editing name of propagated signals from the port label is not supported. You can still edit the port block name and internal signal name using the port label cue. When you click the cue, the port signal name field is empty because the internal signal does not have a name.
Subsystem port labels show the name of propagated signals when all these conditions are true:
价值Icon displayparameter for the underlying port block isSignal name
。
The internal signal within the subsystem is connected but does not have a name.
The propagated signal has a name.
You can change the name of theSubsystem阻止并修改您使用任何其他块的方法。例如,您可以:
应用块蒙版隐藏子系统内容,使其看起来像具有自己的图标和参数对话框的原子块。有关更多信息,请参阅掩盖基本面。
使用块回调来响应子系统建模操作,例如处理错误,删除子系统中的块或线路或关闭子系统。有关块属性(例如回调)的更多信息,请参见Specify Block Properties。
The读/写许可parameter of aSubsystemblock controls the level of access allowed for the subsystem.
Note
Restricting read or write access does not prevent the access restrictions from being changed. To hide proprietary information, consider using a protected model. For more information, seeExplore Protected Model Capabilities。
When a subsystem is stored in a custom library, you can use the读/写许可父库块上的参数以控制该块的链接实例的访问。只要库链接保持完整,限制访问就可以防止人们查看或修改子系统的内容,同时仍允许他们在模型中使用它。有关更多信息,请参阅Linked Blocks。
Simulink.BlockDiagram.copyContentsToSubsystem