You can log simulation data to the workspace, or to a temporary file on disk, for debugging and verification. Data logging lets you analyze how internal block variables change with time during simulation. For example, you might want to see that the pressure in a hydraulic cylinder is above some minimum value or compare it against the pump pressure. If you log simulation data, you can later query, plot, and analyze it without rerunning the simulation.
There are two methods of simulation data logging: you can store the data directly in a workspace variable, or you can stream data to a temporary file on disk and have the workspace variable point to that temporary file. For more information on the second method, see Stream Logging Data to Disk. In either case, you interact with the logged simulation data through the simulation log variable.
Simulation data logging can replace connecting sensors and scopes to track simulation data. These blocks increase model complexity and slow down simulation. Log and Plot Simulation Data shows how you can log and plot simulation data instead of adding sensors to your model. It also shows how you can print the complete logging tree for a model and plot simulation results for a selected variable.
You can log data either for the whole model, or on a block-by-block basis. In the second case, the workspace variable will contain simulation data for selected blocks only. To log data for selected blocks only, you have to:
Set the logging configuration parameter
Select the blocks in your model
You can perform these two steps in any order. For more information, see Log Data for Selected Blocks Only.
After running the simulation, you can use the Simscape™ Results Explorer tool to navigate and plot the data logging results.
For additional information on how you can query, plot, and analyze data by accessing the
simulation log variable, see the reference pages for the classes
simscape.logging.Series, and their associated
You can also configure your model to automatically record Simscape logging data, along with the rest of the simulation data obtained from a model run, using the Simulation Data Inspector. Set up your model to log simulation data, either for the whole model or on a block-by-block basis, and enable data recording. Simulate the model, and then open the Simulation Data Inspector and view the results. For detailed information on how to enable data recording and how to configure and use the Simulation Data Inspector, see Simulation Data Inspector in Your Workflow (Simulink).
To make your model simulation and data logging compatible with the
parfor command, select the Single simulation
output check box on the Data Import/Export pane of the
Configuration Parameters dialog box. In this case, Simscape log data will be part of the single output object instead of being stored as a
separate workspace variable. For more information, see Single simulation output (Simulink).
Simulation data logging is not supported for:
Rapid Accelerator mode
If you use the
sim command with a
'StopTime' name-value pair, the Simscape logging results are not updated.