主要内容

Memory and Data Usage by Logging Method

When you log simulation data, the software saves the data to one or more of these locations, depending on the logging technique used:

  1. User-specified directory (disk)

  2. Temporary repository (disk)

  3. Memory (RAM)

Simulation data can include any combination of output, signal, time, state, and data store logging data. How you choose to save simulation data depends on factors like your model configuration, the types of data you want to log, or how you plan to use the logged data. For more information about choosing logging methods, see Save Simulation Data.

Your choice of logging technique affects where the simulation data is saved. You can prioritize either memory or disk usage through your choice of logging technique. The maximum size of logged data in the temporary repository is constrained only by available disk space. Running multiple simulations without clearing the repository can lead to large amounts of data stored on disk. For more information about minimizing the temporary disk space used when logging simulation data, see Reduce Memory or Disk Space Usage.

To interact with data during simulation, select techniques that log data to memory either automatically or on demand. Data is loaded into memory on demand when you use logging techniques that:

  • Save data to the workspace

  • Do not require adding blocks to your model

  • Log data in Dataset format

When signals are loaded into memory on demand, the variables appear in the workspace, but the signal data is not loaded into memory until it is needed. Examples of logging techniques that load data into memory on demand include signal logging and logging output data with a root-level Outport block.

When a simulation generates more data than your computer can efficiently hold in working memory, log data to persistent storage. For more information about minimizing the memory requirements when logging simulation data, see Log Data to Persistent Storage.

This table shows an overview of memory and disk usage for several common logging techniques.

Logging MethodDisk UsageMemory Usage
Signal loggingDMR file in a temporary directory

Minimal

Data loads into memory on demand when you access the out.logsout variable in the workspace.

Output

DMR file in a temporary directory

Minimal

Data loads into memory on demand when you access the out.yout variable in the workspace.

Log data to file

DMR file in a temporary directory

MAT or MLDATX file in a user-specified directory

None

Data never loads into memory.

To Workspace blockDMR file in a temporary directory

High

Data automatically loads into memory in the variable out.simout when the simulation is paused or stopped.

To File block

MAT file in a user-specified directory

None

Data never loads into memory.

Record block

DMR file in a temporary directory

If you select Record to File, data is also stored on disk to a MAT, MLDATX, Excel®, or Parquet file in a user-specified directory

Default configuration: None.

With the default configuration, the Record block never loads data into memory.

If you select Record to Workspace: High

When you select Record to Workspace, data automatically loads into memory to the variable out.recordout when the simulation is paused or stopped.

Scope blockDMR file in a temporary directory

High.

Data automatically loads into memory in the variable out.ScopeData when the simulation is paused or stopped.

Data Store Memory blockDMR file in a temporary directory

Minimal

Data loads into memory on demand when you access the out.dsmout variable in the workspace.

States and Final statesDMR file in a temporary directory

Minimal

Data loads into memory on demand when you access the out.xout or out.xFinal variable in the workspace.

Signal Logging Disk and Memory Usage

To log signals throughout a model without adding blocks, mark the signals for logging. For more information, see Save Signal Data Using Signal Logging.

When you use signal logging to log data, the software saves data to a DMR file in a temporary directory. The software loads the signal data into memory on demand to the workspace variable logsout or out.logsout when you access it. To optimize memory usage, signal data is loaded into memory only when needed.

Suppose you use signal logging to save data from a signal named mySig. Suppose also that the model is configured to return a single simulation output. When you configure a model to return data as a single simulation output, the software stores signal logging data in the variable out.logsout. The out.logsout variable appears in the MATLAB workspace when the simulation is paused, stopped, or completed. However, the signal data is not loaded into memory until you need it. For example, the software loads the data into memory when you access the signal.

mySignal = get(out.logsout,"mySig");

Logged Output Data Disk and Memory Usage

To log output data at the top level of a model hierarchy, connect a signal to an Outport block.

When you log output data, the software saves the data to a DMR file in a temporary directory. The software loads the output data into memory on demand to the workspace variable yout or out.yout when you access it. To optimize memory usage, output data is loaded into memory only when needed.

Suppose you use an Outport block at the top level of a model hierarchy to save data from a signal named myOutput. Suppose also that the model is configured to return a single simulation output. When you configure a model to return data as a single simulation output, the software stores output data in the variable out.yout. The out.yout variable appears in the MATLAB workspace when the simulation is paused, stopped, or completed. However, the data is not loaded into memory until you need it. For example, the software loads the data into memory when you access the signal.

myOutputSignal = get(out.yout,"myOutput");

Disk and Memory Usage for Data Logged to File

To save all simulation data logged in Dataset format to a file rather than the workspace, open the Configuration Parameters dialog box. In the Data Import/Export pane, select Log data to file and enter a filename in the text box. You can save data to a MAT file or an MLDATX file by specifying the file extension. Alternatively, you can configure the model to log Dataset format data to a file programmatically.

set_param(mdl,LoggingToFile="on",LoggingFileName="myFileName.mldatx")

When you select the Log data to file parameter, the software saves all data logged in Dataset format to disk in two files:

  • A DMR file in the temporary repository, which the Simulation Data Inspector uses when you visualize and analyze the logged data

  • A MAT or MLDATX file in a user-specified directory

This approach is useful for large simulations because it avoids memory overhead by keeping all logged data on disk while still supporting post-simulation analysis in the Simulation Data Inspector and MATLAB.

To Workspace Block Disk and Memory Usage

To log a signal into memory, in your model, connect a To Workspace block to the signal you want to log.

When you log a signal using a To Workspace block, the software saves the data to a DMR file in a temporary repository. The software loads the data logged by the To Workspace block into memory when the simulation is paused, stopped, or completed.

The To Workspace block does not log data in Dataset format, so any signals logged using this method are still loaded into memory even if you select the Log data to file configuration parameter. Ensure that there is sufficient memory to load the data into the workspace before logging signals using the To Workspace block.

To File Block Disk and Memory Usage

To log a signal to a MAT file, connect the signal to a To File block. Each MAT file contains the data for one signal. To save multiple signals in a single file, use the Record block or the Log data to file configuration parameter.

When you log a signal using a To File block, the software saves the data to a MAT file in a user-specified location. The software does not save the data to a temporary DMR file. Data logged by the To File block is never loaded into memory.

Record Block Disk and Memory Usage

To view and log signals to the workspace, a file, or both, use the Record block.

When you save data using the default configuration of the Record block, the software saves data only to the DMR file in the temporary repository. Data is not loaded into memory or saved to a file in a permanent directory.

To log data to the workspace, in the Record block, select Record To Workspace. With this configuration of the block, the software saves data to the temporary DMR file and loads data into memory when the simulation is paused, stopped, or completed. Ensure that there is sufficient memory to load the data into the workspace before logging signals using the Record To Workspace setting in the Record block.

To log data to a file, in the Record block, select Record To File and specify the file name, extension, and location. With this configuration of the block, the software saves data to the temporary DMR file and to the file type and location that you specify. You can use the Record block to save data to a MAT, MLDATX, Excel, or Parquet file.

If you select both Record To Workspace and Record to File, the software saves data to the temporary DMR file, the permanent file that you specify, and loads data into memory.

Logged Scope Block Signals Memory and Data Usage

To log data displayed in a Scope block to the workspace, in the Scope block, select Log data to workspace. For more information, see Save Simulation Data Using Scope Block.

When you log a signal using a Scope block, the software saves the data to a DMR file in a temporary repository. The software loads the data logged by the Scope block into memory when the simulation is paused, stopped, or completed. Ensure that there is sufficient memory to load the data into the workspace before logging signals using the Scope block.

Logged States Memory and Data Usage

To save state data, in the Configuration Parameters dialog box, enable States or Final states logging. For more information, see Save State Information.

When you log states or final states, the software saves data to the DMR file in a temporary directory. The software loads the state data into memory on demand when you access it. State data is saved to the workspace variable xout or out.xout. Final state data is saved to the variable xFinal or out.xFinal. To optimize memory usage, state information is loaded into memory only when needed.

Logged Data Stores Memory and Data Usage

To log data stores, in the Configuration Parameters dialog box, enable Data stores logging and use either a Data Store Memory block or a Simulink.Signal object to log data. For more information, see Log Data Stores.

When you log data stores, the software saves data to a DMR file in a temporary directory. The software loads the data into memory on demand to the workspace variable dsmout or out.dsmout when you access it. To optimize memory usage, data stores are loaded into memory only when needed.

See Also

Blocks

Model Settings

Topics