Main Content

Using Data Stores Across Multiple Models

此示例显示了如何使用和记录本地数据存储。它还显示了如何定义,使用和记录全局数据存储,以在引用模型中共享全局数据。

打开示例模型

Open the example models. The top modelsldemo_mdlref_dsmreferences modelssldemo_mdlref_dsm_botandsldemo_mdlref_dsm_bot2。数据存储的日志记录已打开sldemo_mdlref_dsmon the Data Import/Export pane of the Configuration Parameters dialog box.

Reference modelsldemo_mdlref_dsm_botamplifies the incoming signal by 5 if the signal is positive or by 2 if the signal is negative and writes the value of this signal to local data storeRefSignalVal。该本地数据存储被配置为在模拟后将所有书面值记录到工作区。此本地数据存储的日志记录参数由记录tab of the block parameters dialog.

Reference modelsldemo_mdlref_dsm_bot2设置名为全局布尔数据存储的值errorcond如果其传入信号的值超出范围(-0.8,0.8),则为真实。顶部模型还监视数据存储errorcond并在两个引用模型的输出之间进行切换,具体取决于该数据存储的值。

使用Simulink®信号对象定义全球数据存储金宝app

To specify to Simulink that the top model and both of the referenced models use the same memory for the data store namederrorcond在每个模型中,创建一个Simulink.Signal目的namederrorcondin a workspace or data dictionary that is visible to each model. Since this object is visible to each model, its scope encompasses the individual models and implies that there is one global data store of that name that is shared among the models. Note that none of the three models contains a Data Store Memory block with a data store name oferrorcond。如果任何模型包含这样的块,则该块将定义模型本地数据存储,这将遮蔽全局数据存储。

Since the objecterrorcond定义全局数据存储,必须明确定义数据类型,,,,复杂,,,,and方面非属性设置的属性。采样时间andStorageclass可以将其作为其继承的值留下,也可以显式设置。

该示例包括一个名为sldemo_mdlref_dsm_data.matthat contains theSimulink.Signal目的errorcond。这preload function of the modelsldemo_mdlref_dsm加载此垫子文件,导致对象加载在基本工作区中。您可以通过在模型资源管理器中选择基本工作区来查看此对象。您还可以从MATLAB®命令提示符创建此对象。以下命令定义此示例中使用的对象:

errorcond= Simulink.Signal; ErrorCond.Description = 'Use to signal that subsystem output is invalid'; ErrorCond.DataType = 'boolean'; ErrorCond.Complexity = 'real'; ErrorCond.Dimensions = 1; ErrorCond.SampleTime = 0.1; ErrorCond.LoggingInfo.DataLogging = true;

记录全球数据存储

要记录所有写入全局数据存储的值,请设置DataLoggingproperty of thelogginginfoproperty of theSimulink.Signal目的。这logginginfo属性还允许其他loggin的规范g parameters such as decimation and maximum points.

金宝appsimulink.logginginfo(hander)datalogging:1 namemode:0 loggingname:''decimimatedata:0删除:2 limitdatapoints:0 maxpoints:5000

Simulate the Model

Now you can simulatesldemo_mdlref_dsm查看输出。参考模型sldemo_mdlref_dsm_botwrites to the data storeerrorcondwhile the top modelsldemo_mdlref_dsm从数据存储中读取。蓝线表示输入sldemo_mdlref_dsm_bot;绿线代表开关块的输出。请注意,当输入信号的幅度出现在范围之外时,输出会切换。

View Logged Results

Both the global data storeerrorcond和本地数据存储RefSignalVal被配置为在仿真后记录所有书面值。这些记录的结果存储在基本工作区中dsmout多变的。

dsmout = Simulink.SimulationData.Dataset 'dsmout' with 2 elements Name BlockPath ____________ ________________________________________ 1 [1x1 DataStoreMemory] ErrorCond '' 2 [1x1 DataStoreMemory] RefSignalVal ...dlref_dsm/A|sldemo_mdlref_dsm_bot/DSM - Use braces { } to access, modify, or add elements using index.

To access the data stored for the local data store, use thegetelement根据名称获取正确的数据存储元素的功能RefSignalVal

>> dsmout.getElement('refsignalval')
金宝appsimulink.simulationdata.datastorememory软件包:simulink.SimulationData属性:名称:'refSignAlval'blockpath:[1x1 simulink.simulationdata.blockpath]范围:'local'dsmwriterblocksss:dsmwriterblockpaths:[1x2 simulink.simulink.simulationdata doive1 dsmulationdata unints unints unints unints unints][1x1次数]

数据存储在一个时间序列场地。

>> plot(dsmout.getElement('RefSignalVal').Values);

To determine which block wrote to the data store at a given time, use theDSMWritersproperty. This array contains a list of indices into theDSMWriterBlockPatharray. For example, the block path of the Data Store Write block that wrote the 5th value to the data store can be obtained as follows:

>> dsm = dsmout.getElement('refsignalval');>> DSM.DSMWRITERBLOCKPATH(DSM.DSMWRITERS(5))
金宝appsimulink.simulationdata.blockpath软件包:simulink.simulationdata block路径:'sldemo_mdlref_dsm/a''sldemo_mdlref_dsm_bot/potitivess/dsw'使用getBlock方法来访问该对象的block路径vectors。

也可以看看

||

Related Topics