主要内容

创建子系统

随着模型的大小和复杂性的增加,您可以通过将块分组到子系统中来简化它。子系统是一组块,您将其分组为一个子系统堵塞。

使用子系统:

  • 建立一个层次结构图,其中子系统堵塞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.

当您制作子系统的副本时,该副本独立于源子系统。要重复使用模型或跨模型的子系统的内容,请考虑引用的子系统,引用模型或链接到自定义库中块的子系统。有关更多信息,请参阅Choose Among Types of Model Components

Types of Subsystems

一个subsystem can be virtual or nonvirtual. Avirtual subsystem在模型中提供图形层次结构,不会影响模型的执行。一个nonvirtual subsystem在模型中执行单个单元。

Tip

For controllers and other standalone components, define a hard boundary around the related blocks by using a nonvirtual subsystem or referenced model. Defining a hard boundary upfront avoids costly refactoring when you want to generate code for the component.

金宝app®classifies nonvirtual subsystems into these types:

Type of Subsystem 描述
原子子系统

子系统that executes as a single unit.

启用子系统

该子系统的执行是由外部输入启用的。

触发子系统

子系统whose execution is triggered by external input.

Function-Call Subsystem

子系统whose execution is controlled by an external function-call input.

Enabled and Triggered Subsystem

子系统whose execution is enabled and triggered by external inputs.

消息触发子系统and信息轮询年代ubsystem 子系统whose execution is triggered by message input.
重置table Subsystem

子系统whose block states reset with an external trigger.

如果一个ction Subsystem

子系统的执行是由如果堵塞。

开关案例行动子系统 子系统whose execution is controlled by aSwitch Case堵塞。
而迭代子系统

子系统that repeats execution during a simulation time step while a logical condition is true.

For Iterator Subsystem 子系统that repeats execution during a simulation time step for a specified number of iterations.
For Each Subsystem

在输入信号的每个元素或子阵列上重复执行并连接结果的子系统。

创建子系统

To create a subsystem, you can:

  • In the Simulink Editor, double-click and start typing the subsystem type, then select the corresponding block from the menu.

  • In the Simulink Editor, drag a selection box to outline the subsystem that you want to create, then select the subsystem type.

  • 拖动子系统堵塞from the Library Browser.

  • Copy and paste a子系统堵塞from a model.

当您从选择框创建子系统时,选择可以是空的,也可以在模型的一个区域中包含多个块。

从动作栏中,选择要创建的子系统的类型。

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.

You can change the type of subsystem after creation.

  • 要使子系统执行为单位,请单击子系统堵塞。On the子系统选项卡,选择是原子子系统

  • To make a subsystem execute conditionally, add a block that corresponds to a control port.

  • 要使子系统无条件执行,请删除与控制端口相对应的块。

将端口添加到子系统

The ports on a子系统块对应于子系统内部的块。

例如,这个子系统块有两个输入端口和一个输出端口。

子系统包含两个企业堵塞s,在1andin2, and oneOutport堵塞,OUT1,对应于子系统堵塞。

To automatically add ports to a子系统堵塞:

  • 单击边缘子系统堵塞, then select the type of port to create.

  • 将一条线拖到子系统堵塞。

  • The corresponding port blocks are added inside the subsystem.

Tip

后自动港口铬eation, the port label on the子系统堵塞is enabled for quick editing. See,Edit Port Labels on Subsystems

To manually add ports, open the subsystem by double-clicking the子系统堵塞, then add the corresponding blocks to the subsystem.

Type of Port 相应的块
Signal port, input 企业堵塞
Signal port, output Outport堵塞
Bus port, input In Bus Element堵塞
Bus port, output 出去公交元素堵塞
控制端口,启用 Enable堵塞
控制端口,触发 扳机堵塞
Control port, function-call 扳机扳机type调成function-call
控制端口,重置 重置堵塞
Control port, action 一个ction Port堵塞
Connection port Connection Port(SIMSCAPE)堵塞

To change the location of a port on a子系统阻止,将端口拖到该侧面任何一侧的新位置子系统堵塞。

一个port is dragged from the left side of the block to the top side of the block.

默认情况下,Simuli金宝appnk标记了端口子系统堵塞。To specify how Simulink labels the ports of a subsystem:

  1. 选择子系统堵塞。

  2. On theFormatSimulink To金宝appolstrip的选项卡,从“Port Labelsmenu. For more information, see显示端口标签

Edit Port Labels on Subsystems

You can directly edit the port labels on these types of subsystem blocks:

  • Regular subsystem

  • 子系统with mask

  • Variant subsystem

  • 图表子系统

    To edit the port label on a subsystem block in the current model:

    1. 指向端口标签。互动端口标签提示(blue box surrounding the port label) appears. Click the cue.

      一个lternatively, select the port and pressF2。The cue enters edit mode.

      在一个上创建新端口子系统堵塞using automatic port creation also enables the port label cue for quick editing.

      可编辑端口标签提示

    2. 一个port selector cueappears 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

    3. 在端口标签提示中输入值,然后按EnterorEsc键, or click away.

      端口选择器提示上方端口标签提示

    4. 编辑端口标签后,Simulink会自动更新子系统中相关端口或信号金宝app的名称。

      子系统内更新的端口名称

    Tip

    在子系统块上进行连续的端口标签编辑:

    • Select a port on the block.

    • Edit the port label and pressEnter。此操作使键盘可以选择端口。

    • 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 一个ction
    没有任何 Editing not supported.
    端口图标

    Updates the names of elements in the subsystem depending on the图标显示parameter of the port.

    例如,如果的价值图标显示parameter of the port is信号名称,然后更新了端口块上的图标和链接信号的名称。

    Note

    对于这种类型的端口标签,编辑后端口标签上显示的信息取决于使用Selector Cue在标签上执行的最终编辑:

    • 如果the initial port label shows the port block name, and the final edit is on the signal name, then the图标显示parameter for the underlying port block automatically updates to信号名称。因此,在编辑后,端口标签默认情况下显示了信号名称。

    • 如果the initial port label shows the port signal name, and the final edit is on the port block name, then the图标显示parameter for the underlying port block automatically updates to端口号。So, after the edit, the port label shows the block name by default.

    端口块名称 更新子系统中端口的块名。对于这种类型的端口标签,您可以仅使用端口选择器提示编辑端口块名称。
    信号名称 Updates the name of the signal linked to the port.

Note

  • 金宝appSimulink不显示端口选择器提示Chart堵塞s.

  • 编辑端口标签子系统堵塞s 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.

  • 不支持来自端口标签的传播信号的编辑名称。金宝app您仍然可以使用端口标签提示编辑端口块名称和内部信号名称。单击提示时,端口信号名称字段为空,因为内部信号没有名称。

    子系统端口标签显示所有这些条件均为真实信号的名称:

    • The value of the图标显示基础端口块的参数为信号名称

    • 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 the子系统堵塞and modify the block the way that you do with any other block. For example, you can:

  • 一个pply block masks to hide the subsystem content, making it appear as an atomic block with its own icon and parameter dialog box. For more information, see掩盖基本面

  • Use block callbacks to perform actions in response to subsystem modeling actions such as handling an error, deleting a block or line in a subsystem, or closing a subsystem. For more information on block properties, such as callbacks, see指定块属性

限制子系统访问

TheRead/Write permissionsparameter of a子系统堵塞controls the level of access allowed for the subsystem.

Note

限制读取或写入访问并不能阻止访问限制更改。要隐藏专有信息,请考虑使用受保护的模型。有关更多信息,请参阅Explore Protected Model Capabilities

When a subsystem is stored in a custom library, you can use theRead/Write permissionsparameter on the parent library block to control access for the linked instances of the block. As long as the library link remains intact, the restricted access can prevent people from viewing or modifying the contents of the subsystem while still allowing them to employ it in a model. For more information, see链接块

See Also

Related Topics