Log and Visualize Data
This example shows how to log variables and interact with the results to visualize the data. You can use different MATLAB and Simulink tools to visualize and interact with the simulation data that you generate.
To open the model, enter:
openExample('sdl/SimpleGearExample')
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.
Visualize with Scope Blocks
The model contains the Sensor(base)
and
Sensor(follower)
Subsystem blocks. Inside the subsystems are sensor blocks that
track physical properties in the network. Scope blocks display
the Simulink signals from these subsystems. 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.
Run the model and open the Scope block to view the output.
You can also use the Probe block to select block variables and output them to a
Scope block. For example, you can bind the
Probe block to the Simple
Gear block in the model and output the base and follower
velocity variables, B.w
and
t.B
, to a
Scope block.
Log and Visualize Select Block Variables
Simscape selective logging lets you select individual block variables that you want to log. You can display the logged data using the Data Inspector tool.
To log selected block variables in the Simple
Gear block, Gear
, and the
Inertia block, Inertia2
:
Select the
Gear
block.In the Simscape Block tab, click Instrumentation Table.
In the Model Data Editor pane, select the
B.w
andtB
variables for theGear
block. Then, select thew
andt
variables for theInertia2
block.
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, run the model and under the Simulation tab, click Data Inspector.
Select B.w
and
w
under
SimpleGear
, which
are the base and follower velocities of the Simple
Gear block, respectively. You can use the Visualizations and
layout button to add a second plot window below the
first. Highlight the bottom plot window and select tB
and t
under SimpleGear
, which are the base and follower torque
values of the Simple Gear block. The signals are
consistent with the Scope block results.
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. To learn more about Simscape data logging, see Log, Navigate, and Plot Simulation Data.
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. You can select any block variable from the model.
The figure displays the base and follower speed of the Simple Gear block in the Simscape Results Explorer tool. However, all variable data for each Simscape block in the model is available in the tool.
See Also
View Simulation Data in Simulation Data Inspector | Simscape Results Explorer