Main Content

Log Data to Persistent Storage

何时登录持续存储

In some cases, logging simulation data can create large amounts of data that are too large for your computer to hold in working memory while also running efficiently. Such situations can include simulations that log many signals, simulations that run for a long time with many time steps, and parallel simulations. When your simulation configuration creates a large amount of data, you can log that data to persistent storage, rather than logging it to working memory.

You can store logged simulation data to persistent storage in a MAT-file. You control logging to persistent storage at the model level. You can enable and disable the feature by changing one model configuration parameter (日志数据集数据文件) without changing the model layout.

If you useDataset用于日志记录的格式,您可以记录每种数据以持续存储:

  • 信号记录 - 使用Dataset仅格式。

  • 状态 - 默认为Dataset格式。您可以使用其他格式。

  • 最终状态 - 要求您清除保存最终操作点parameter

  • Output — Defaults toDataset格式。

  • Data stores — UsesDataset仅格式。

默认情况下,禁用了记录到持续存储的存储,因此记录的数据存储在MATLAB中®工作区。对于大多数型号,登录工作空间更简单,因为它可以避免加载和保存记录文件。与访问记录的数据相比,访问记录到持续存储的数据需要一些其他步骤。对于简短的仿真,登录到MATLAB工作区的速度比记录持续存储更快,并且可能使用的内存更少。

Limitations for Logging to Persistent Storage

  • Only data logged inDataset格式存储在垫子中。以其他格式记录的数据存储在MATLAB工作区中。

  • To use persistent storage for logging final states data, you cannot enable the配置参数>Data Import/Export+保存最终操作点

  • 模拟步进和快速重新启动不支持登录以持续存储。金宝app

  • During simulation, you cannot load data from the persistent storage file directly into the model. Create objects that reference the data in the file and then load the referencing object.

Alternative Approaches for Reducing Logging Memory Usage

当您需要模拟创建大量数据的模型并且您不想将仿真数据记录到持久存储时,请考虑使用其中一种替代方案。

  • 限制工作空间中存储的仿真数据量。

    您可以使用其中一种或多种技术限制工作空间中存储的仿真数据的量。有关详细信息,请参阅指定信号值

    Technique Description
    指定拆卸因子 Skip samples when exporting data.
    限制数据点 Limit the number of samples saved to be only the most recent samples.
    Specify intervals for logging Specify ranges of time steps for logging.

    如果限制了工作空间中存储的仿真数据的量,则记录的数据可能不包含一些时间步骤,这些步骤对于测试和分析模型至关重要。

  • Use a提交block for each signal that you want to log.

    Connecting a提交块到信号,表明您想将记录的数据存储在垫子文件中,而不是在MATLAB工作区中。但是,这种方法:

    • 是一个信号的方法,可以杂波模型with multiple提交blocks attached to individual signals.

    • 为每个创建一个单独的垫子提交block, instead of the single file created when you log to persistent storage.

登录到持续存储

  1. Specify the kinds of logging to perform (for example, signal logging and output logging) and the variable names for the logging data.

  2. In the model diagram, mark selected signals for signal logging.

  3. UseDataset用于记录数据的格式。以任何其他格式记录的数据存储在工作区中。

    • 信号记录和数据存储记录使用Dataset仅格式。输出,状态和最终状态记录的默认格式为Dataset

    • 对于最终状态记录,清除保存最终操作点配置参数。

  4. 启用登录持续存储并指定输出垫件名称。

    • Select the日志数据集数据文件配置参数。

    • 指定要使用的垫子文件。请勿在其他语言环境中使用一个语言环境中的文件名。

  5. To save the loggedDatasetdata using时间序列or时间表元素,设置Dataset signal format配置参数。默认格式为时间序列。这时间表format is helpful for MATLAB combining logged data from multiple simulations. For details about the时间表format, seeDataset signal format

  6. 模拟模型。

Enable Logging to Persistent Storage Programmatically

You can programmatically log to persistent storage. To enable logging to persistent storage, use theLoggingToFileandloggingfilename名称值对SIM命令或set_param命令。

要启用您要使用的记录方法,请将这些参数设置为'在', as applicable:

  • 信号

  • SaveState

  • SaveFinalState

  • SaveOutput

  • DSMLogging

To log output, states, and final states data to persistent storage, set theSaveFormat参数为'Dataset'

To log final states data to persistent storage, set theSaveOperatingPoint'off'

How Simulation Data Is Stored

Logging to persistent storage saves logged simulation data in the specified MAT-file. The data is stored as aSimulink.SimulationData.Datasetobjects for each type of logging that usesDataset格式。这Datasetelements are stored as either时间序列or时间表对象,取决于您如何设置Dataset signal formatparameter. For details about the时间表format, seeDataset signal format

Dataset文件中的对象名称是您用于记录的变量的名称。例如,如果使用默认信号记录变量logsout, 这Datasetobject in the MAT-file islogsout

Save Logged Data from Successive Simulations

您使用的保存从连续模拟记录的数据的方法取决于您是否正在执行并行仿真。

Without Using Parallel Simulations

每次您在不使用并行模拟的情况下模拟模型时,Simulink金宝app®除非您在模拟之间更改文件名,否则覆盖垫子文件的内容。当您使用金宝appsimulink.simulationdata.datasetrefobject that references data in the MAT-file to retrieve data in the file, it retrieves the most recent version of the data. To preserve data from an earlier simulation, use one of these approaches:

  • 在模拟之间,使用配置参数>Data Import/Exportpane to specify a different name for the MAT-file for logging.

  • 在模拟之间,保存垫子文件的副本。使用与指定为持久存储的垫子文件的名称不同的文件名,或移动垫子文件。

  • 编程为每个模拟运行指定一个新文件名。

If you run multiple simulations that overlap in time, use a unique MAT-file for each model that you log to persistent storage.

如果将用于记录的文件名更改为持久存储,则要访问已记录数据,请使用以下方法:

  • 创建一个金宝appsimulink.simulationdata.datasetrefobject.

  • 要匹配新文件名,请更改地点property of theDatasetRef对象。

For details about usingDatasetRef访问已记录数据的对象,请参阅加载大数据进行模拟

使用并联模拟

For parallel simulations, for which you specify an array of input objects, if you log to file, Simulink:

  • 为每个模拟创建一个垫子

  • 创建金宝appsimulink.simulationdata.datasetref对象可以访问MAT文件中的输出数据,并将这些对象包括在仿真图object data

  • 启用捕获argument for simulation

For more information about parallel simulations, see运行多个模拟

也可以看看

职能

Related Topics