变体结构
为模型中的结构变化生成和管理代码
使用 Simulink® 中的变体模块,您可以在单个模型中表示一个组件的各种不同设计。每个设计选择项都可作为一个变体选择项纳入模型的单个层或单独层次结构中。这种模型有固定的通用结构和一组有限的变体选择项,这些变体选择项激活与否取决于您选择的变体控制项。有关详细信息,请参阅什么是变体以及何时使用变体。变体激活时间决定了激活选择项的时间,以及在生成的代码中是仅包括活动选择项,还是同时包括活动和非活动选择项。有关激活时间的信息,请参阅Activate Variant During Different Stages of Simulation and Code Generation Workflow。
主题
生成代码
- Generate Code for Variant Subsystem Blocks
Generate code for specific implementation of component represented using Variant Subsystem block. - Generate Code for Variant Source and Variant Sink Blocks
Generate code for specific implementation of component represented using Variant Source and Variant Sink blocks. - Generate Code for Variant Start and Variant End Blocks
Generate code for specific implementation of component represented using Variant Start and Variant End blocks. - Generate Code for Model References Connected to Variant Blocks
Reuse and incrementally load, build, and generate code for multiple variations of a component. - Generate Code from Nested Variant Subsystem with Code Compile and Startup Activation
This example illustrates howcode compile
andstartup
variant activation time can be used together in two nested variant subsystems.
对接变体模块
- Conditionalize Export Function Calls in Code using Variant Blocks
Generate code for export function calls conditionally using variant blocks.
通过优化代码最大限度地提高代码的可靠性和安全性
- Compile Code Conditionally for Variations of Component Represented Using Variant Block
Conditionally compile code for different implementations of a component using variant blocks. - Run Executables for Variant Blocks Without Recompiling Code for Changing Active Choices Using Startup Activation Time
This example explains how to generate code for multiple implementations of a component represented using a Variant Subsystem block withstartup
activation time. - Propagate Variant Conditions to Define Variant Regions Outside Variant Subsystems to Promote Consistency and Reduce Errors
Propagate variant conditions outside a Variant Subsystem block to adapt its interface according to the state of underlying blocks. - Remove Inactive Variant Components from Generated Code at Compile Time When No Active Choices Exist
Exclude inactive variant components from generated code at compile time. - Manage Variant Components to Pass Specified Values from Inactive Variant Subsystems with No Active Choice
Exclude inactive variant components from code generated for Variant Subsystem block at compile time.
控制和管理变体
- Organize Variant Control Macros in Same Header File
Aggregate variant control macros into a single header file using custom storage classes. - Represent Variant Conditions of Enumerated Type in Generated Code
Represent variant control variables meaningfully in the generated code by using enumerated types. - Generate Code for Variant Elements Within Buses
Generate code for buses with elements having different variant conditions. - Use Simulink.Parameter Type of Variant Control Variables for Code Generation in Variant Blocks
If you intend to generate code for a model containing variant blocks, specify variant control variables as
objects.Simulink.Parameter