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. This way, you can view and analyze the data while the simulation is running. Set up your model to log simulation data, either for the whole model or on a block-by-block basis. Enable data streaming by selecting the Record data in Simulation Data Inspector check box on the Simscape pane of the Configuration Parameters dialog box. When you simulate the model, as soon as the streamed data becomes available, the Simulation Data Inspector button in the model toolbar highlights. Open the Simulation Data Inspector to view the data during simulation and to compare data for different simulation runs. For detailed information on how to configure and use the Simulation Data Inspector, see Inspect and Analyze Simulation Results.
If you have a Parallel Computing Toolbox™ license, you can make your model simulation and data logging compatible with
parfor command by selecting 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 a separate
workspace variable. For more information, see Single simulation output. All the other data logging workflows
described here assume that you clear the Single simulation output check
box and that you interact with the logged Simscape data through the simulation log workspace variable.
Simulation data logging is not supported for:
Rapid accelerator mode
Partitioning local solver
If you use the
sim command with a
'StopTime' name-value pair, the Simscape logging results are not updated.