主要内容

复合信号的类型

为了降低模型中的视觉复杂性,您可以将信号组合为复合信号。复合信号包含的信号称为元素。Elements retain their separate identities, which let you extract them from the composite signal.

您可以根据复合信号类型访问名称或索引的复合信号元素。

  • Name-based composite signals allow for signal hierarchy. They are generically calledbuses

  • 基于索引的复合信号是平坦的,无论您是否在阶段创建它们。他们要求所有输入信号具有相同的数据类型。

When you group signals into a composite signal, you can decide whether they affect simulation and code generation.

  • Avirtualcomposite signal simplifies the visual appearance 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.

  • Anonvirtualcomposite signal visually and functionally groups signals, affecting both simulation and code generation.

Models can use a combination of these composite signal types.

Composite Signal Feature 基于名称的访问 Index-Based Access
视觉分组

虚拟巴士

MuxSignal

Functional Grouping

非虚拟巴士

Concatenated Signal

您可以在编译或模拟模型后通过其线样式识别复合信号类型。

Line Style 复合信号类型
虚拟巴士
Nonvirtual bus
Nonscalar signal when theNonscalar Signalsinformation overlay is enabled (includes index-based composite signals)
基于索引的复合信号,包含非虚拟巴士

虚拟巴士

该模型显示了一个包含信号的虚拟总线a,b, 和c

公共汽车创建者blocks create buses within a subsystem or model.总线选择器块提取指定的元素。

This model shows an equivalent virtual bus passing through a subsystem boundary.

出去公交元素blocks create a bus at a subsystem or model interface.In Bus Elementblocks extract specified elements of a bus at a subsystem or model interface.

您可以使用虚拟巴士来:

  • 包含具有不同样本率的总线元素。

  • Cross model reference boundaries.

To specify and validate the properties of a virtual bus, you can specify a金宝appsimulink.bus目的。

要创建虚拟巴士,请参阅小组信号线进入虚拟巴士

非虚拟巴士

该模型显示了包含信号的非虚拟巴士a,b, 和c

公共汽车创建者blocks create buses within a subsystem or model.总线选择器块提取指定的元素。

You can use nonvirtual buses to:

  • 包装总线数据作为生成的C代码中的结构。

  • Construct an array of buses.

  • 通过S功能与外部代码接口。

  • Have bus data crossMATLAB功能block or Stateflow®图表边界。

  • Display and log buses with aScope堵塞。

全部元素of a nonvirtual bus must use the same sample time. You can use aRate Transitionblock to change the sample time of an individual signal or of all signals in a bus.

A金宝appsimulink.bus对象必须定义要进行非虚拟的公共汽车。当您选择该公共汽车时作为非虚拟巴士的输出parameter. Selecting this parameter causes simulation and code generation to apply the structure defined by theBus目的。When this parameter is cleared, theBusobject only validates the properties of the bus.

总线的类型可以在生成的代码的效率,大小和可读性上产生重大影响。为了使公共汽车出现在生成的代码中,必须是非虚拟的。仅虚拟总线的元素出现在生成的代码中。

例如,假设一辆巴士通过单位延迟堵塞。为简单起见,公共汽车只包含三个要素:a,b, 和c。This table shows the effect of the作为非虚拟巴士的输出生成代码上的参数。

Generated Code 虚拟巴士 非虚拟巴士

模型_ types.h文件

虚拟巴士es do not require type definitions.

Busobjects appear in the generated code as structures.

typedef struct { real_T a; real_T b; real_T c; } BusObject;

模型。H文件

生成的代码定义了一个单位延迟block for each element of the virtual bus.

typedef struct { real_T UnitDelay_1_DSTATE; /* '/Unit Delay' */ real_T UnitDelay_2_DSTATE; /* '/Unit Delay' */ real_T UnitDelay_3_DSTATE; /* '/Unit Delay' */ } DW_模型_t;

生成的代码定义了一个单位延迟block for the nonvirtual bus, using theBusObjectstructure.

typedef struct {busObject unitdelay_dstate;/ *'/单位延迟' */} dw_模型_t;

要创建非虚拟巴士,请参阅创建非虚拟巴士

如果您打算为使用总线的模型生成代码,请参见Generate Efficient Code for Bus Signals(Simulink Coder)。为非虚拟巴士生成代码可能会导致多个公交车的副本。

Concatenated Signal

该模型显示了一个并排放置输入矩阵的串联信号。

基质连接块创建串联信号。元素可以是向量或矩阵,具体取决于您如何配置此块。这选择器块根据指定指标提取信号。提取的信号可以与输入信号分组不同。

您可以在数学操作中使用串联信号。

矢量联合或者基质连接块,信号必须具有相同的数据类型。当数据类型为Bus对象,输入必须是非虚拟巴士。

Concatenated nonvirtual buses are also known as an一系列公共汽车。在一系列公共汽车中,所有元素都是使用相同的非虚拟公共汽车Bus对象指定属性。一系列公共汽车等同于MATLAB中的一系列结构®。You can use an array of buses to model a multichannel system. While all the channels have the same properties, each of the channels may have a different value.

在此模型中矢量联合街区创建了一系列公共汽车。

有关公共汽车阵列的更多信息,请参阅将公交车结合成一系列公共汽车

MuxSignal

This model shows a mux signal that places the three input signals side by side.

Muxblock creates mux signals. TheDemuxblock extracts all signals, which may be grouped differently than the input signals. The选择器块根据指定指标提取信号。提取的信号可以与输入信号分组不同。

You can use a mux signal to perform computations on multiple vectors. You can also use aMux块创建函数调用向量。

输入信号Muxblock can be any combination of scalars, vectors, and mux signals, but they must have the same data type and numeric type. The signals in the output mux signal appear in the same order as the input signals for theMux堵塞。You can use multipleMuxblocks to create a mux signal in stages, but the result is flat as if you used a singleMux堵塞。

相关话题