Main Content

Log and Visualize Data

Logging data allows you to capture and store simulation results for later use. After you log data, you can analyze it to understand the system behavior, validate your models, or optimize system performance. You can use different MATLAB and Simulink tools to visualize and interact with the simulation data that you generate.

This example shows how to log variables and interact with the results to visualize the data. To open the model, enter:

openExample('sdl/SimpleGearExample')

Model that represents a simple gear.

Visualize with Scope Blocks

The model uses Subsystem blocks that contain component blocks to sense the physical network data and display it to a Scope block. Scope blocks display Simulink signals. You can output physical signals from Simscape sensor blocks to the Scope block using a PS-Simulink Converter block. This model uses Motion Sensor blocks and Torque Sensor blocks to output physical signal data to the Scope block.

Motion Sensor block connected to PS-Simulink Converter block.

Run the model and open the Scope block to view the output.

Baseline Scope block results for the model.

You can also use the Probe block to select block variables and output them to a Scope block.

Log and Visualize Select Block Variables

You can retrieve individual block variable data using selective logging and display it using the Data Inspector tool.

Enable logging for the Simple Gear block, Gear, and the Inertia block, Inertia2.

  1. Select the Gear block.

  2. In the Simscape Block tab, click the Log Variables drop down menu and select Instrumentation Table.

  3. In the Model Data Editor pane, select the B.w and tB variables for the Gear block. Then, select the w and t variables for the Inertia2 block.

  4. To enable logging for a block, select the block, and click the Log Variables button. Enable logging for the Gear and Inertia2 blocks.

Model with Gear and Inertia2 blocks enabled for selective logging.

Selective logging uses Simulink data logging. The gray logging badge on a Simscape block indicates that Simulink data logging is disabled. To enable Simulink logging, first open the Configuration Parameters dialog by clicking Model Settings in the Modeling tab. Then, in the Data Import/Export section, select Signal logging. Confirm the logging badge on both blocks changes to blue.

To view the results, first run the model. Then, under the Simulation tab, click the Data Inspector button.

Select SimpleGear.Gear.B.w and SimpleGear.Inertia2.w. You can use the Visualizations and layout Visualizations and layout button. button to add a second plot window below the first . Highlight the bottom plot window and select SimpleGear.Gear.tB and SimpleGear.Inertia2.t. The signals are consistent with the Scope block results.

The Simulink Data Inspector shows the same results as the Scope block.

To learn more about selective logging, see Log Selected Block Variables.

Log and Visualize All Model Data

Simscape data logging logs all block variables in a model or in selected blocks. To enable Simscape data logging, in the Simscape section of the Configuration Parameters dialog, select Signal logging. The data saves to a workspace variable, and you can view the results in the Simscape Results Explorer. To view the results, under the Simulation tab, click the Simscape Results Explorer button.

The Simscape Results Explorer shows the same speed data as the Scope block.

You can select any block variable from the model. To learn more about Simscape data logging, see Log, Navigate, and Plot Simulation Data.

See Also

|