Main Content

Types of Composite Signals

To reduce visual complexity in a model, you can combine signals into composite signals. The signals that a composite signal contains are calledelements。Elements retain their separate identities, which let you extract them from the composite signal.

You can access composite signal elements by name or index, depending on the composite signal type.

  • Name-based composite signals allow for signal hierarchy and are called公共汽车

  • Index-based composite signals are flat, regardless of whether you create them in stages. They require that all input signals have the same data type.

当您将信号分组为复合信号时,您可以决定它们是否影响模拟和代码生成。

  • 一种虚拟的复合信号简化了视觉外观of a model by combining two or more signal lines into one line. It does not group the signals in any functional sense and, therefore, does not affect simulation or code generation. By accessing elements directly, virtual composite signals execute faster than nonvirtual composite signals in simulations and generated code.

  • 一种非虚拟Composite signal visually and functionally groups signals, affecting both simulation and code generation.

模型可以使用这些复合信号类型的组合。

复合信号功能 Name-Based Access 基于索引的访问
Visual Grouping

Virtual Bus

MUX信号

功能组

Nonvirtual Bus

串联信号

您可以在编译模型后通过其线样式识别复合信号类型。当您为复合信号创建线路或打开包含复合信号的模型时,复合信号具有与标量信号相同的线样式。编译模型并显示复合线样式造型tab, selectUpdate Model

编译后的复合线样式 Composite Signal Type
Virtual bus line style Virtual bus
非虚拟公交线风格 非虚拟巴士
非信号线 基于索引的复合信号非标志信号information overlay is enabled
一系列公交线风格 Index-based composite signal that contains nonvirtual buses (called an一种rray of buses

Virtual Bus

This model shows a virtual bus that contains signals一种,,,,b,,,,一种ndC

在总线创建器块和总线选择器块之间具有虚拟总线的型号

公共汽车Creator块在子系统或模型中创建总线。公共汽车Selector块提取总线的指定元素。

该模型显示了通过子系统边界的等效虚拟总线。

Model with a virtual bus that connects two subsystems

Out Bus Element块在子系统或模型接口处创建总线。在公交元素中块提取在子系统或模型接口处的总线指定元素。

您可以使用虚拟总线包含具有不同样本时间的总线元素。

要定义虚拟总线的属性,您可以指定一个Simulink.Busobject data type or specify element attributes with在公交元素中一种ndOut Bus Elementblocks.

To create a virtual bus, seeGroup Signal Lines into Virtual Buses

Nonvirtual Bus

This model shows a nonvirtual bus that contains signals一种,,,,b,,,,一种ndC

Model with a nonvirtual bus between a Bus Creator block and a Bus Selector block

公共汽车Creator块在子系统或模型中创建总线。公共汽车Selector块提取总线的指定元素。

该模型显示了使用模型参考边界的等效非虚拟总线Out Bus Element一种nd在公交元素中blocks.

具有连接两个子系统的非虚拟巴士的模型

You can use nonvirtual buses to:

  • Package bus data as structures in the generated C code.

  • 构建一系列公共汽车。

  • Interface with external code through an S-function.

  • 有巴士数据交叉MATLAB Function块或状态流®Chart boundaries.

  • 展示和记录巴士Scope堵塞。

非虚拟总线的所有元素都必须使用相同的样本时间。您可以使用Rate Transition阻止以更改单个信号的样本时间或总线中所有信号的样本时间。

一种Simulink.Busobject data type must define the bus you want to make nonvirtual. A bus becomes nonvirtual when you select a block parameter such asOutput as nonvirtual bus。选择使总线非虚拟型导致模拟和代码生成应用于该结构公共汽车object. When the bus is virtual, the公共汽车对象仅验证总线的属性。

这type of bus can make a significant difference in the efficiency, size, and readability of the generated code. For a bus to appear in the generated code, it must be nonvirtual. Only the elements of a virtual bus appear in the generated code.

For example, suppose a bus passes through aUnit Delay堵塞。For simplicity, the bus contains only three elements:一种,,,,b,,,,一种ndC。该表显示了非虚拟总线对生成代码的效果。

生成的代码 Virtual Bus Nonvirtual Bus

model_types.hfile

虚拟总线不需要类型定义。

公共汽车对象出现在生成的代码中作为结构。

typedef struct {real_t a;real_t b;real_t c;} busObject;

model。hfile

这generated code defines oneUnit Delay虚拟总线的每个元素的块。

typedef struct {real_t unitdelay_1_dstate;/ *'/单位延迟' */real_t unitdelay_2_dstate;/ *'/单位延迟' */real_t unitdelay_3_dstate;/ *'/单位延迟' */} dw_model_T;

这generated code defines oneUnit Delay使用非虚拟巴士的街区busObject结构体。

typedef struct { BusObject UnitDelay_DSTATE; /* '/Unit Delay' */ } DW_model_T;

To create a nonvirtual bus, seeCreate Nonvirtual Buses

If you intend to generate code for a model that uses buses, see为总线信号生成有效的代码(金宝appSimulink编码器)。Generating code for nonvirtual buses can result in multiple copies of some buses.

串联信号

This model shows a concatenated signal that places the input matrices side by side.

在矩阵连接块和两个选择器块之间具有串联信号的模型

Matrix Concatenate块创建连接的信号。元素可以be either vectors or matrices, depending on how you configure this block. TheSelectorblock extracts signals based on specified indices. The extracted signals can be grouped differently than the input signals.

You can use concatenated signals in mathematical operations.

To group signals with aVector ConcatenateorMatrix Concatenateblock, the signals must have the same data type. When the data type is a公共汽车object, the inputs must be nonvirtual buses.

串联的非虚拟巴士也被称为一种rray of buses。In an array of buses, all elements are nonvirtual buses that use the same公共汽车object to specify properties. An array of buses is equivalent to an array of structures in MATLAB®。您可以使用一系列总线来建模多通道系统。尽管所有通道都具有相同的属性,但每个通道都可能具有不同的值。

In this model, aVector Concatenateblock creates an array of buses.

Model with an array of buses between a Vector Concatenate block and a Selector block

For more information on arrays of buses, seeGroup Nonvirtual Buses in Arrays of Buses

MUX信号

该模型显示了一个MUX信号,该信号将三个输入信号并排放置。

MUX块,Demux块和选择器块之间具有MUX信号的模型

Muxblock creates mux signals. ThedemuxBlock提取所有信号,这些信号可能与输入信号分组不同。这Selectorblock extracts signals based on specified indices. The extracted signals can be grouped differently than the input signals.

您可以使用MUX信号在多个向量上执行计算。您也可以使用Muxblock to create a vector of function calls.

Input signals for aMux块可以是标量,向量和MUX信号的任何组合,但是它们必须具有相同的数据类型和数字类型。输出MUX信号中的信号与输入信号的顺序相同Mux堵塞。您可以使用多个Mux块以分阶段创建MUX信号,但结果是平坦的,好像您使用了一个Mux堵塞。

Related Topics