主要内容

将多个模型参数组合成一个结构

这个例子展示了如何通过编程方式配置一个引用模型的多个实例,通过使用结构对同一个块参数使用不同的值。

配置引用模型以使用分组到结构中的模型参数

当您想要添加、重命名或删除参数时,可以使用结构来减少维护工作。对于结构,模型的数学功能是相同的。

的结构替换参数值ex_model_arg_ref而且ex_model_arg,请遵循以下步骤。

开放模式ex_model_arg_ref.该模型代表了一个可重用的算法。

open_system (“ex_model_arg_ref”

属性中存在的每个参数对象都包含一个字段的结构ex_model_arg_ref工作区。为每个字段指定一个值。

structForInst1。增益= 3.17;structForInst1。Coeff = 1.05;

将结构存储在金宝app仿真软件。参数对象。

structForInst1Param = 金宝appSimulink.Parameter(结构forinst1);

复制金宝app仿真软件。参数对象放入ex_model_arg_ref模型的工作空间。在本例中,为对象的副本命名structArg

modelWorkspace = get_param(“ex_model_arg_ref”“ModelWorkspace”);assignin (modelWorkspace“structArg”,复制(structForInst1Param));

配置structArg作为唯一的模型参数。

set_param (“ex_model_arg_ref”“ParameterArgumentNames”“structArg”

ex_model_arg_ref模型,设置获得参数的增益块structArg.gain并设置分子参数structArg.coeff

set_param (“ex_model_arg_ref /增益”“获得”“structArg.gain”) set_param (“ex_model_arg_ref /离散滤波器”...“分子”“structArg.coeff”

将现有结构复制为structForInst2Param

structForInst2Param = copy(structForInst1Param);

将两个结构中的字段值设置为用于在model块中设置模型参数值的相同数字。

structForInst1Param.Value。Coeff = 0.98;structForInst1Param.Value。增益= 2.98;structForInst2Param.Value。Coeff = 1.11;structForInst2Param.Value。增益= 3.34;

开放模式ex_model_arg.该模型表示使用可重用算法的多个实例的系统模型。

open_system (“ex_model_arg”

对于模型实例模型,设置structArgstructForInst1Param.对于模型实例Model1,设置structArgstructForInst2Param

instSpecParamsStruct = get_param(“ex_model_arg /模式”“InstanceParameters”);instSpecParamsStruct1 = get_param(“ex_model_arg / Model1”“InstanceParameters”);instSpecParamsStruct(1)。值=“structForInst1Param”;instSpecParamsStruct1(1)。值=“structForInst2Param”;set_param (“ex_model_arg /模式”“InstanceParameters”, instSpecParamsStruct);set_param (“ex_model_arg / Model1”“InstanceParameters”, instSpecParamsStruct1);

使用总线对象作为结构的数据类型

你可以使用金宝app仿真软件。公共汽车对象作为结构的数据类型。总线对象确保实例特定结构的特征,例如字段的名称和顺序,与模型工作空间中的结构特征匹配。

要将结构的数据类型设置为总线对象,请执行以下步骤。

使用金宝appSimulink.Bus.createObject函数创建总线对象。对象中元素的层次结构与结构字段的层次结构相匹配。对象的默认名称为slBus1

金宝appSimulink.Bus.createObject (structForInst1Param.Value);

通过复制总线对象来重命名它。

myParamStructType = copy(slBus1);

使用总线对象在基本工作区中设置参数对象的数据类型。

structForInst1Param。数据类型=“巴士:myParamStructType”;structForInst2Param。数据类型=“巴士:myParamStructType”

structArg对象,设置数据类型总线:myParamStructType

temp = getVariable(modelWorkspace,“structArg”);Temp = copy(Temp);temp.DataType =“巴士:myParamStructType”;assignin (modelWorkspace“structArg”,复制(临时));close_system (“ex_model_arg_ref”, 0) close_system (“ex_model_arg”,0)

相关的话题