金宝appSimulink.VariantVariable类
包裹:金宝app
创建一个变体参数对象
Description
这Simulink.VariantVariable
class creates a variant parameter object. You can specify multiple values for each object. You can also specify properties such as dimension, data type, and so on. Each value of the object is associated with a variant condition expression. Set the parameter values and properties in the object, then reference the object from the block.
Before you create a newSimulink.VariantVariable
目的,,,,create aSimulink.VariantControl
目的representing the variant control variable to be used in theSimulink.VariantVariable
目的。
笔记
You can create the variant parameter object only in a base or in a data dictionary.
Creation
creates an empty variant parameter object.p
= Simulink.VariantVariable
创建一个或多个指定的变体参数对象p
= 金宝appsimulink.variantvariable(名称,价值
)名称,价值
pair arguments. Using this syntax, you can specify multiple values for the object and associate each value with a variant condition expression. You can also specify other properties of the object such as data types, storage class, dimensions, and so on.
输入参数
Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN
,,,,whereName
是参数名称和value
is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.
Before R2021a, use commas to separate each name and value, and encloseName
in quotes.
Example:'Specification', 'Pspec', 'Choices', {'V==1', 4.5, 'V==2', 9.5}
规格
-properties of variant parameter object
金宝appsimulink.parameter
目的name
properties of variant parameter object such as data type, dimensions, storage class, and so on, specified as the金宝appsimulink.parameter
目的。这default storage class of a金宝appsimulink.parameter
目的isAuto
。如果将存储类指定为Auto
,,,,the value of the object is inline to the literal value in the generated code. If you specify the storage class of the object anything other thanAuto
,,,,the object is represented as tunable parameters using symbolic names in the generated code. For more information, seeOptions to Represent Variant Parameters in Generated Code(Embedded Coder)。
Example:'Specification', 'Pspec'
Choices
-变体条件和价值
单元阵列
变体条件和价值,,,,specified as a struct. During simulation, when a variant condition evaluates totrue
,其关联的值变得活跃。当变体条件评估为错误的
,其关联的值变得不活跃。相同变体参数的两个值必须与相同的变体条件相关联。
You can specify the variant condition as boolean MATLAB®包含一个或多个操作数和操作员的表达式。看变体控制变量(操作数)的类型在变体参数中and类型在变体参数中。
您可以指定数字,枚举或金宝appsimulink.parameter
类型。看,Numeric Variant Control Values for Rapid Prototyping of Variant Parameters,,,,Improve Code Readability of Variant Parameters Using Enumerated Types, 和Reuse Variant Parameter Values from Handwritten Code Using Simulink.Parameter Variables。
Example:'Choices', {'V==1', 4.5, 'V==2', 9.5}
Methods
public Methods
addChoice |
将选择添加到变体参数对象 |
GEtChoice |
Return choices of variant parameter object |
setChoice |
修改变体参数对象的现有选择 |
removeChoice |
Remove choices from variant parameter object |
Specialized Operators and Functions
这se methods specialize standard MATLAB operators and functions for objects in this class.
BITCMP |
performs bit-wise complement on input. |
等式 |
比较输入是否相等。 |
GT |
Compares if the first input is greater than the second input. |
mrdivide |
Divides the first input by the second input. |
or |
执行逻辑或输入。 |
Uminus |
Negates the input. |
bitor |
在位置或输入方面执行。 |
GE |
Compares if the first input is greater than or equal to the second input. |
le |
Compares if the first input is less than or equal to the second input. |
mtimes |
乘以输入。 |
加 |
添加输入。 |
Uplus |
Returns the value of the input. |
and |
执行逻辑和输入。 |
bitshift |
按指定数量的位置换档。 |
上尉 |
Compares if the first input is less than the second input. |
ne |
比较输入是否不相等。 |
bitand |
在位置和输入方面执行。 |
Bitxor |
performs bit-wise XOR on inputs. |
minus |
Subtracts the second input from the first input. |
not |
返回逻辑而不是输入。 |
Examples
Numeric Variant Control Values for Rapid Prototyping of Variant Parameters
当您仍在构建模型时,数值允许您快速原型变体值。数值可以帮助您更多地专注于构建变体值,而不是开发激活这些选择的表达式。
You can define numeric control values in locations listed inStorage Locations for Variant Control Variables (Operands) in Variant Blocks。
打开slexVariantParameters
model.
open_system('slexVariantParameters')
在MATLAB编辑器中,选择t指定变体heir simplest form as numeric values inSimulink.VariantVariable
对象K1
andK2
。
k1 = 金宝appsimulink.variantvariable('Choices',,,,{'v == 1',3.5,'v == 2',,,,8.5})
K1= VariantVariable with 2 choices: Condition Value _________ _____ V == 1 3.5000 V == 2 8.5000 Specification: '' Use getChoice, setChoice, addChoice, removeChoice to access, modify, add or remove choices
k2 = 金宝appsimulink.variantvariable('Choices',,,,{'v == 1',,,,4.5,,,,'v == 2',,,,9.5})
K2= VariantVariable with 2 choices: Condition Value _________ _____ V == 1 4.5000 V == 2 9.5000 Specification: '' Use getChoice, setChoice, addChoice, removeChoice to access, modify, add or remove choices
Once you successfully create theSimulink.VariantVariable
对象,,,,you can modify them by using the methods described inpublic Methodsor from thevariantVariable
dialog box.
通过定义控制变量来激活一个变体值之一,,,,v
, 和setting its value to1
在一个Simulink.VariantControl
目的。
v= Simulink.VariantControl('价值',,,,1,,,,'ActivationTime',,,,'update diagram')
v= VariantControl with properties: Value: 1 ActivationTime: 'update diagram'
When you simulate the model, the conditionV == 1
评估true
。K1
is assigned a value of3.5
andK2
is assigned a value of8.5
。
sim('slexVariantParameters')
If you change the value ofv
to2
,s金宝appimulink®设定了K1
andK2
to4.5
and9.5
在模拟过程中。您可以更改价值v
使用此命令或从Simulink.VariantControl
dialog box.
v。value = 2; sim ('slexVariantParameters')
金宝appsimulink.parameterType of Variant Control Variables for Code Generation of Variant Parameters
如果您打算为包含变体参数的模型生成代码,请指定变体控制变量为金宝appsimulink.parameter
对象。金宝appsimulink.parameter
对象允许您指定其他属性,例如数据类型和存储类,并控制生成代码中变体控制变量的外观和放置。
You can define a variant control variable of type
金宝appsimulink.parameter
only in the base workspace or in a data dictionary. Defining金宝appsimulink.parameter
控制变量类型的变体在面具或model workspace is not supported. For more information on storage locations for variant control variables, seeStorage Locations for Variant Control Variables (Operands) in Variant Blocks。金宝appsimulink.parameter
对象within structures and that have data types other than金宝appsimulink.bus
对象are not supported.
打开slexVariantParameters
model.
open_system('slexVariantParameters')
In the MATLAB Editor, define a金宝appsimulink.parameter
目的。
VSS_MODE= Simulink.Parameter; VSS_MODE.Value = 1; VSS_MODE.DataType ='int32';vss_mode.coderinfo.storageclass ='风俗';vss_mode.coderinfo.customstorageclass ='定义';vss_mode.coderinfo.customattributes.headerfile ='demo_macros.h';
变体控制变量定义为金宝appsimulink.parameter
对象可以在Storage Classes for Different Variant Activation Times(Embedded Coder)。
You can also convert a scalar variant control variable into a金宝appsimulink.parameter
目的。For more information, seeConvert Variant Control Variables into Simulink.Parameter Objects。
指定目的as a variant control inSimulink.VariantVariable
对象
K1
andK2
。
k1 = 金宝appsimulink.variantvariable('Choices',,,,{'V == 1',3.5,'V == 2',,,,8.5})
K1= VariantVariable with 2 choices: Condition Value _________ _____ V == 1 3.5000 V == 2 8.5000 Specification: '' Use getChoice, setChoice, addChoice, removeChoice to access, modify, add or remove choices
k2 = 金宝appsimulink.variantvariable('Choices',,,,{'V == 1',,,,4.5,,,,'V == 2',,,,9.5})
K2= VariantVariable with 2 choices: Condition Value _________ _____ V == 1 4.5000 V == 2 9.5000 Specification: '' Use getChoice, setChoice, addChoice, removeChoice to access, modify, add or remove choices
Once you successfully create theSimulink.VariantVariable
对象,,,,you can modify them by using the methods described inpublic Methodsor from thevariantVariable
dialog box.
通过定义控制变量来激活一个变体值之一v
and setting its value toVSS_MODE
在一个Simulink.VariantControl
目的。
v= Simulink.VariantControl('价值',vss_mode,'ActivationTime',,,,'code compile')
v= VariantControl with properties: Value: [1x1 Simulink.Parameter] ActivationTime: 'code compile'
When you simulate the model, the conditionV == 1
评估true
。K1
is assigned a value of3.5
, 和K2
is assigned a value of8.5
。
sim('slexVariantParameters')
If you change the value ofVSS_MODE
to2
,s金宝appimulink®设定了K1
andK2
to4.5
and9.5
在模拟过程中。您可以更改价值v
使用此命令或从Simulink.VariantControl
dialog box.
vss_mode.value = 2;v.value = vss_mode;sim('slexVariantParameters')
Generate code from the model. For information on how to generate code, seeGenerate Code Using Embedded Coder(Embedded Coder)
这GEnerated code contains both线性
and非线性
choices in preprocessor conditionals#如果
and#elif
because of thecode compile
activation time. The variant control variablev
is defined using a macro —#定义
directive — in the header filedemo_macros.h.
You can control the appearance and placement ofv
in the generated code and prevent optimizations from eliminating storage forv
using the storage class property. For more information, seeStorage Classes for Different Variant Activation Times(Embedded Coder)。
%demo_macros.h%/* Exported data define */%% / *自定义存储类的定义:定义 * /%#定义v2/* Referenced by:% *'/gain' %* '/Gain1' %*/%#endif /* RTW_HEADER_demo_macros_h_ */%%/*
金宝appsimulink.variant对象,用于变异参数的变体条件重复使用
After identifying the variant values that your model requires, you can construct complex variant conditions to control the activation of your variant parameter values by defining variant conditions asSimulink.Variant
对象。Simulink.Variant
对象enable you to reuse common variant conditions across models and help you encapsulate complex variant condition expressions.
You can define a variant control variable of type
Simulink.Variant
only in the base workspace or in a data dictionary. DefiningSimulink.Variant
控制变量类型的变体在面具或model workspace is not supported. For more information on storage locations for variant control variables, seeStorage Locations for Variant Control Variables (Operands) in Variant Blocks。Simulink.Variant
within structures are not supported.
打开slexVariantParameters
model.
open_system('slexVariantParameters')
In the MATLAB® Editor, encapsulate variant control expressions asSimulink.Variant
对象。
线性Controller=Simulink.Variant('v == 1');NonLinearController=Simulink.Variant('v == 2');
指定Simulink.Variant
对象作为变体控件Simulink.VariantVariable
对象K1
andK2
。
k1 = 金宝appsimulink.variantvariable('Choices',,,,{'LinearController',,,,3.5,,,,'NonLinearController',8.5})
K1= VariantVariable with 2 choices: Condition Value ___________________ _____ LinearController 3.5000 NonLinearController 8.5000 Specification: '' Use getChoice, setChoice, addChoice, removeChoice to access, modify, add or remove choices
k2 = 金宝appsimulink.variantvariable('Choices',,,,{'LinearController',,,,4.5,,,,'NonLinearController',9.5})
k2 = variantvariable具有2个选择:条件值___________________ _____ linearController 4.5000 nonelarearcontroller 9.5000规格:''使用getchoice,setchoice,addchoice,addChoice,addChoice,removeChoice,removeChoice,removeChoice,removeChoice forcess,修改,添加或删除选择选择选择,
Once you successfully create theSimulink.VariantVariable
对象,,,,you can modify them by using the methods described inpublic Methodsor from thevariantVariable
dialog box.
Activate one of the variant values by defining aSimulink.VariantControl
目的v
and setting its value to1
。
v= Simulink.VariantControl('价值',,,,1,,,,'ActivationTime',,,,'update diagram')
v= VariantControl with properties: Value: 1 ActivationTime: 'update diagram'
When you simulate the model, the conditionV == 1
评估true
。K1
is assigned a value of3.5,,,,
andK2
is assigned a value of8.5
。
sim('slexVariantParameters')
If you change the value ofv
to2
,s金宝appimulink®设定了K1
andK2
to4.5
and9.5
在模拟过程中。您可以更改价值v
使用此命令或从Simulink.VariantControl
dialog box.
v。value = 2; sim ('slexVariantParameters')
Using this approach, you can develop complex variant condition expressions that are reusable.
Extended Capabilities
C/C++ Code Generation
使用MATLAB®CODER™生成C和C ++代码。
For variant parameters associated with the
启动
激活时间,您可以通过安装为活动和非活动选择生成代码金宝app®CODER™或嵌入式编码器®。For variant parameters associated with the
code compile
激活时间:您必须安装Simulink Coder仅对变体参数的活动值生成代码。使用代码使用Simulink Coder仅当变金宝app体参数的值具有相同的维度时,才能支持。
您必须安装嵌入式编码器以生成用于变异参数的活动和不活动值的代码。使用嵌入式编码器生成代码,对于具有相同尺寸和不同尺寸的变体参数值支持。金宝app
For more information on code generation with variant parameters, seeOptions to Represent Variant Parameters in Generated Code(Embedded Coder)。
版本历史记录
BeispielÖffnen
Sie HabenEineGeänderte版本死亡。möchtensie dieses beispiel mit ihrenänderungenÖffnen?
matlab-befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
选择一个网站
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:。
您还可以从以下列表中选择一个网站:
How to Get Best Site Performance
选择中国网站(中文或英语)以获得最佳场地性能。其他Mathworks乡村网站未针对您所在的访问进行优化。
美洲
- América Latina(Español)
- 加拿大(English)
- 美国(English)
欧洲
- Netherlands(English)
- Norway(English)
- Österreich(德意志)
- 葡萄牙(English)
- Sweden(English)
- 瑞士
- United Kingdom(English)