Main Content

使用Variant参数以不同的值重用块参数

You may have a set of requirements where the structure of the model remains the same, but the values of the parameters for each requirement are different. In this scenario, you can create a single model with fixed structure and create parameters with a finite set of values where each value corresponds to different requirements. Parameters that have multiple values are called变体参数。V.ariant parameters can be defined in a MATLAB®基础工作区或数据字典。

变体参数的每个值必须与变体条件表达式关联。您可以具有与变体条件相关联的多个变体参数,不提供两个值属于同一参数。当条件表达式评估到true那all the values associated with that condition become active and are assigned to the corresponding parameters. If you change the value of the variant control variable, a different set of values is assigned to the parameters. This way, variant parameters allow you to logically bind a set of values across different parameters to a condition expression, and the values are assigned to the parameter based on the variant condition that evaluates totrue

万博1manbetx®selects the active value of a variant parameter during update diagram time, during code compile time, or during the model startup time. For more information, see在模拟和代码生成工作流程的不同阶段激活变体

考虑这个模型。这Gain参数的Gainblock is a variant parameter with its value set toK.。变量K.有两个值:3.5and8.5。Simulink chooses active value ofK.基于变量控制变量的值V.。如果v == 1evaluates totrue, 的价值K.is set to3.5。如果v == 2evaluates totrue, 的价值K.is set to8.5

Variant参数,增益块中具有多个值。每个值与变体条件表达式相关联。

何时创建变体参数

变体参数提供了一种为块参数值不同不同的系统设计一种模型的方法。您可以根据系统组分组不同的值集以模拟。每组值与变体条件表达式相关联。在模拟期间,如果变体条件评估为true那then all the values associated with that condition become active. To change the set of active values, change the value of the variant control variable and run the simulation again.

考虑此模型,代表具有多种配置的汽车系统。这些配置虽然在若干方面类似,但在诸如发动机中的燃料消耗,发动机尺寸或汽缸数量的值中可以不同。您可以使用Variant参数来模拟不同值的变体参数来设计多个块。

如何在模型中使用Variant参数的示例来表示具有多种配置的汽车系统

在该模型中,燃料消耗,发动机尺寸和汽缸数具有变体参数FC.es.那andnc。变体参数的值基于变量控制变量的值V.。For example, ifv == 1evaluates totrue,那么值FC.is set to30.es.is set to1000那andncis set to4.

Advantages of Using Variant Parameters

使用基于模型的设计中的变体参数提供了几个优点:

  • V.ariant parameters provide you a way to design one model for many systems.

  • 变体参数有助于重用块。这种方法通过降低复杂性来提高工作流程速度。

  • 变体参数可帮助您在不同的块参数值之间切换多个模拟,代码生成或测试工作流程。

  • 您不需要重新生成用于变体参数的不同值的代码,因为生成的代码具有用于参数的每个变体值的预处理器条件。

使用变体参数的限制

在基于模型的设计中使用变体参数也有限制:

  • 确定变体参数的活动值的变型控制变量的值必须是数值,枚举值或a万博1manbetxSimulink.Parameter.Parameter.object.

  • Only the values of the variant parameters change based on the variant condition that evaluates totrue。其他属性,例如存储类,数据类型等,无论变体条件如何保持相同。

  • 变体参数只能在基础工作区或数据字典中定义。

  • 变体参数不支持生成AutoSAR目标的代码。万博1manbetx

也可以看看

|(嵌入式编码器)

Related Topics