在Simulink模型中使用数据对象 您所在的位置:网站首页 simulink模型参数设置 在Simulink模型中使用数据对象

在Simulink模型中使用数据对象

2022-11-12 02:25| 来源: 网络整理| 查看: 265

可以将参数保存下来,方便运行时修改

Use Data Objects in Simulink Models在Simulink模型中使用数据对象To specify simulation and code generation options for signals, block parameters, and states by modifying variables in a workspace or data dictionary, use data objects. Associate the objects with signals, parameters, and states in a model diagram.若要通过修改工作区或数据字典中的变量来指定信号、块参数和状态的模拟和代码生成选项,请使用数据对象。将对象与模型图中的信号、参数和状态关联起来。

Use Parameter Objects使用参数对象

You can use parameter objects, instead of numeric MATLAB variables, to specify values for block parameters. For example, to create and use a Simulink.Parameter object named myParam to specify the Gain parameter of a Gain block:您可以使用参数对象,而不是数字MATLAB变量,来指定块参数的值。例如,创建和使用Simulink。参数对象myParam来指定增益块的增益参数:

1 In the model, on the Modeling tab, under Design, click Property Inspector.在模型中,在Modeling选项卡的Design下,单击PropertyInspector。2 In the model, click the target Gain block. The Property Inspector shows the properties and parameters of the block.在模型中,单击目标增益块。PropertyInspector显示块的属性和参数。3 Set the value of the Gain parameter to myParam.将Gain参数的值设置为myParam。4 Next to the parameter value, click the action button

and select Create.在参数值旁边,单击操作按钮并选择Create。5 In the Create New Data dialog box, set Value to Simulink.Parameter(15.23) and click在“创建新数据”对话框中,将Value设置为Simulink.Parameter(15.23),然后单击Create.创造。

The Simulink.Parameter object, myParam, appears in the base workspace. The property dialog box shows that the object stores the parameter value 15.23 in the Value property.Simulink.参数对象myParam出现在基工作区中。属性对话框显示该对象在Value属性中存储参数值15.23。6 Use the property dialog box to specify other characteristics for the block parameter by adjusting the object properties. For example, to specify the minimum and maximum values the parameter can take, use the Minimum and Maximum properties.使用属性对话框通过调整对象属性为块参数指定其他特征。例如,若要指定参数可以采用的最小值和最大值,请使用Minimum和Maximum属性。During simulation, the Gain parameter now uses the value 15.23.在模拟过程中,增益参数现在使用值15.23。To share lookup table data by using Simulink.LookupTable and Simulink.Breakpoint objects, see “Package Shared Breakpoint and Table Data for Lookup Tables” on page 37-29.使用Simulink共享查找表数据。查找表和Simulink。断点对象,请参阅第37-29页上的“包共享断点和查找表的表数据”。

Use Signal Objects使用信号对象

You can associate a signal line or block state, such as the state of a Unit Delay block, with a signal object.可以将信号线或块状态(如UnitDelay块的状态)与信号对象关联。For Signals关于信号

To use a signal object to control the characteristics of a signal in a model, create the object in a workspace by using the same name as the signal.若要使用信号对象来控制模型中信号的特征,请使用与信号相同的名称在工作空间中创建对象。

1 In the model, on the Modeling tab, click Model Data Editor.在模型中,在Modeling选项卡上,单击modeldataeditor。2 In the Model Data Editor, select the Signals tab.在模型数据编辑器中,选择Signals选项卡。3 In the model, select the target signal. The Model Data Editor highlights the row that corresponds to the signal.在模型中,选择目标信号。模型数据编辑器突出显示与信号相对应的行。4 In the Model Data Editor, in the Name column, give the signal a name such as mySig.在“模型数据编辑器”的“名称”列中,为信号指定一个名称,例如mySig。5 Click the button

next the signal name. Select Create and Resolve.单击信号名称旁边的按钮。选择创建和解决

6 In the Create New Data dialog box, set Value to Simulink.Signal. Use the Location drop- down list to select a workspace to store the object (the default value is Base Workspace). Click Create.在“创建新数据”对话框中,将Value设置为Simulink。信号。使用Location下拉列表选择一个工作区来存储对象(默认值为BaseWorkspace)。点击创建。

The Simulink.Signal object mySig appears in the target workspace. Simulink selects the signal property Signal name must resolve to Simulink signal object, which forces the signal in the model to use the properties that the signal object stores. To learn how to control the way that signal names resolve to signal objects, see “Symbol Resolution” on page 67-127.Simulink.信号对象mySig出现在目标工作区中。Simulink选择信号属性Signalname必须解析为Simulink信号对象,这迫使模型中的信号使用信号对象存储的属性。要了解如何控制信号名称解析为信号对象的方式,请参阅第67-127页的“符号解析”。

The property dialog box of the new object opens.打开新对象的属性对话框。7 Use the property dialog box to specify the signal characteristics. Click OK. To configure the signal programmatically:使用属性对话框指定信号特征。点击确定。要以编程方式配置信号:% Create the signal object. mySig = Simulink.Signal; mySig.DataType = 'boolean'; % Get a handle to the block port that creates the%创建信号对象。MysigSimulink.信号;mySig。方法的块端口的句柄% target signal.目标信号百分比。portHandles = get_param('myModel/myBlock','portHandles'); outportHandle = portHandles.Outport;Porthandles获得param(‘mymodel/myblock’,‘portHandles’);

% Specify the programmatic port parameter 'Name'. set_param(outportHandle,'Name','mySig')%指定编程端口参数‘Name’.setparam(outportHandle,‘Name’,‘mySig’)

% Set the port parameter 'MustResolveToSignalObject'. set_param(outportHandle,'MustResolveToSignalObject','on')%设置端口参数“MustResolveToSignalObject”.Set参数(outportHandle,‘MustResolveToSignalObject’,‘on’)

To configure a root-level Outport block programmatically, you must use a slightly different technique:要以编程方式配置根级Outport块,必须使用略有不同的技术:

% Create the signal object. mySig = Simulink.Signal; mySig.DataType = 'boolean';% Create the Signal object. mySig Simulink. Signal;

% Specify the programmatic block parameter 'SignalName'. set_param('myModel/myOutport','SignalName','mySig')%指定编程块参数‘SignalName’.setparam(‘mymodel/myoutport’、‘SignalName’、‘mySig’)

% Set the block parameter 'MustResolveToSignalObject'. set_param('myModel/myOutport','MustResolveToSignalObject','on')%设置块参数‘MustResolveToSignalObject’.Setparam(‘mymodel/myoutport’,‘MustResolveToSignalObject’,‘on’)

For States对于国家

You can use a signal object to control the characteristics of a block state, such as that of the Discrete- Time Integrator block.您可以使用信号对象来控制块状态的特性,例如离散时间积分器块的特性。

1 In the model, on the Modeling tab, click Model Data Editor.在模型中,在Modeling选项卡上,单击modeldataeditor。2 In the Model Data Editor, select the States tab.在模型数据编辑器中,选择States选项卡。3 In the model, select the block that harbors the target state. The Model Data Editor highlights the row that corresponds to the state.在模型中,选择包含目标状态的块。模型数据编辑器突出显示与状态对应的行。4 In the Model Data Editor, in the Name column, give the state a name such as myState.在“模型数据编辑器”的“名称”列中,为状态指定一个名称,例如myState。5 Click the button

next to the state name. Select Create and Resolve.单击州名旁边的按钮。选择“创建和解决”。

6 In the Create New Data dialog box, set Value to Simulink.Signal. Use the Location drop- down list to select a workspace to store the object (the default value is Base Workspace). Click Create.

在“创建新数据”对话框中,将Value设置为Simulink。信号。使用Location下拉列表选择一个工作区来存储对象(默认值为BaseWorkspace)。点击创建。

The Simulink.Signal object myState appears in the target workspace. Simulink selects the block parameter State name must resolve to Simulink signal object, which forces the state in the model to use the properties that the signal object stores. To learn how to control the way that state names resolve to signal objects, see “Symbol Resolution” on page 67-127.

Simulink.信号对象myState出现在目标工作区中。Simulink选择块参数State名称必须解析为Simulink信号对象,这迫使模型中的状态使用信号对象存储的属性。若要了解如何控制状态名称解析为对象信号的方式,请参阅第67-127页的“符号解析”。

The property dialog box of the new object opens.

打开新对象的属性对话框。

7 Use the property dialog box to specify the state characteristics. Click OK. To configure the state programmatically:

使用属性对话框指定状态特征。点击确定。要以编程方式配置状态:

% Create the signal object. myState = Simulink.Signal; myState.DataType = 'int16';

% Create the Signal object. myState Simulink. Signal; myState. DataType‘ int16’ ;

% Set the state name in the block. set_param('myModel/myBlock','StateName','myState')

%在block.Set参数中设置状态名(“mymodel/myblock”、“StateName”、“myState”)

% Set the port parameter 'StateMustResolveToSignalObject'. set_param('myModel/myBlock','StateMustResolveToSignalObject','on')

%设置端口参数‘StateMustResolveToSignalObject’.Setparam(‘mymodel/myblock’,‘StateMustResolveToSignalObject’,‘on’)



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有