Reduce Memory or Disk Space Usage
Depending on your operating system specifications and the logging techniques used, logging simulation data can consume substantial memory or disk resources. For example, logging big data can be memory-intensive, while running many simulations in a single session can require significant disk space.
When you log simulation data, the software saves the data to one or more of these locations, depending on the logging technique used:
MAT, MLDATX, or similar file in a user-specified directory (disk)
DMR file in a temporary repository (disk)
Memory (RAM)
To reduce the memory demands or disk space required for the temporary DMR file, choose from the options in this flowchart. To explore related content, click the corresponding box in the image.
Reduce Temporary Disk Storage
All logged data, except data logged using the To File block, is stored in the logging repository, or Simulation Data Inspector repository, as a DMR file. By default, the maximum size of the DMR file is constrained only by the available disk space. The repository is located in a temporary directory with the default name Tempdir. To locate the repository, use Simulink.sdi.getSource. Logged simulation data is stored in the repository for the duration of a MATLAB session. When you end your MATLAB session, both the data and the file are deleted.
Clear Logging Repository
To prevent logged simulation data from accumulating in the DMR file, periodically start a new Simulation Data Inspector session or clear the repository. Logged data and the Simulation Data Inspector share the same temporary repository. Signals are always logged to the repository, even when you are not using the Simulation Data Inspector to visualize data.
To clear the temporary repository, use Simulink.sdi.clear. Export any data you want to keep before clearing the temporary repository. Some logging techniques, such as signal logging, use on-demand loading. When the software loads data on demand, a variable is created in the workspace, but the data itself remains on disk until accessed. By default, Simulink.sdi.clear exports this on-demand data from the current run to the workspace. To clear the repository faster and without loading on-demand data into memory, set Export=false.
For example, suppose that you log simulation data using a combination of signal logging, an Outport block, a To Workspace block, and a Record block configured to record data to the workspace.
out =
Simulink.SimulationOutput:
logsout: [1x1 Simulink.SimulationData.Dataset]
recordout: [1x1 Simulink.SimulationData.Dataset]
simout: [1x1 timeseries]
tout: [51x1 double]
yout: [1x1 Simulink.SimulationData.Dataset]
SimulationMetadata: [1x1 Simulink.SimulationMetadata]
ErrorMessage: [0x0 char] The software loads signal logging and output data into memory on demand, while a To Workspace block or a Record block that is configured to record data to the workspace loads data into memory when the simulation is paused, stopped, or completed. All four signals have a variable in the workspace, but only simout and recordout are loaded into memory before being needed.
Without accessing the data, clear the repository and set Export=false.
Simulink.sdi.clear(Export=false)
The data logged using the To Workspace and Record blocks is still accessible because these blocks automatically load data into memory.
toWorkspaceData = out.simout
timeseries
Common Properties:
Name: ''
Time: [51x1 double]
TimeInfo: [1x1 tsdata.timemetadata]
Data: [51x1 double]
DataInfo: [1x1 tsdata.datametadata]
More properties, MethodsThe signal logging and output data is no longer accessible because it was never loaded into memory.
sigLoggingData = out.logsout
sigLoggingData =
Simulink.SimulationData.Dataset 'logsout' with 0 elements
- Use braces { } to access, modify, or add elements using index.Decrease Archived Run Limit
One way to reduce the size of the temporary DMR file is to limit the number of runs stored in the Simulation Data Inspector archive. By default, the Simulation Data Inspector retains 20 runs in the archive. To lessen disk space usage, reduce the number of archived runs using Simulink.sdi.setArchiveRunLimit.
Limit Storage Space Available for Logged Data
To manage the size of logged data, use one or both of these options:
To directly control the size of logged data, specify the maximum size of the DMR file using
Simulink.sdi.setMaxDiskUsage.To ensure a certain amount of free disk space when logging data, specify the minimum amount of disk space to leave free using
Simulink.sdi.setRequiredFreeSpace.
By default, logged data has no maximum size limit, but at least 100 MB of disk space must remain free. For more information, see Specify Minimum Disk Space Requirement or Maximum Size for Logged Data.
Move Temporary Repository Location
By default, the software logs data to the DMR file in the temporary directory on your computer. To move the repository file to another location with more disk space, use Simulink.sdi.setStorageLocation.
Note
Logging data to a network location can degrade performance.
Disable Logging to DMR File
When you want to only view data during simulation and not save the values, disable logging to the temporary repository. To disable all logging to the DMR file, use Simulink.sdi.setRecordData with an input value of false. For more information, see View Data Only During Simulation.
Note
If you disable logging to the DMR file, you can only view data during simulation. Data is not available after simulation.
If your machine has more RAM than disk space, configure the DMR file to be retained entirely in memory rather than disk using Simulink.sdi.setStorageMode.
Reduce Memory Consumption
In some cases, logging simulation data can create large amounts of data that are too big for your computer to hold in working memory while also running efficiently. Such situations include simulations that log many signals, simulations that run for a long time with many time steps, and parallel simulations. Use these techniques to reduce memory consumption.
Log Data to File
Some simulations, like those that log big data, create too much data to load into memory at once. To log big data from a simulation that is too large to fit into memory, save the data to persistent storage instead of to the workspace. To save all simulation data logged in Dataset format to a file rather than the workspace, in 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")
For more information, see Log Data to Persistent Storage.
Use Logging Methods That Load Data Into Memory on Demand
Some logging techniques that log data to the workspace, such as using a To Workspace block, automatically load data into memory. Other logging techniques, such as signal logging, load data into memory on demand. If your model logs many signals to the workspace using techniques that automatically load data into memory, consider using techniques that load data into memory only when needed. For more information about how different logging techniques save data, see Memory and Data Usage by Logging Method.
Limit Data Points Logged During Simulation
In some situations, you might not need to log signal values for every time step in a simulation. In these cases, depending on your requirements, you can use one or more of these strategies limiting the size of logged data:
Decimation — Log every nth signal value.
Limit data points to last — Log only the last n signal values.
Logging intervals — Specify specific time intervals in which to log data.
For more information, see Specify Signal Values to Log.
Override Signal Logging Settings
To log less data without making changes to the model in the Simulink® Editor, you can override the signal logging settings. The signal override settings apply only to signals that are marked for signal logging. By overriding signal logging settings, you can avoid recompiling a model and reduce memory overhead. Use the override settings to limit logged data in one or more of these ways:
Log a subset of signals that are marked for signal logging
Log portions of a model hierarchy
Log a subset of sample points
For more information, see Override Signal Logging Settings.