When you log simulation data in a model, you can view the simulation results on an XY visualization in the Simulation Data Inspector. Then, you can replay the simulation to animate the relationships between the signals in your model. This example simulates a model and plots data logged in the simulation using Time Plot and XY visualizations in the Simulation Data Inspector. The example also shows how to inspect the plotted data using replay controls and cursors.
The model in this example simulates the dynamics of a bouncing ball, logging the velocity and position of the ball as outputs.
Because the model is configured to log output data, the signals connected to the Outport blocks log to the workspace and the Simulation Data Inspector. Simulate the model and open the Simulation Data Inspector.
To plot the data on an XY visualization, you need to add the visualization to the layout. By default, the Simulation Data Inspector uses Time Plot visualizations for each subplot in the layout.
To add an XY visualization to your layout, open the Visualization Gallery by selecting Edit View from the Layouts menu.
From the Visualization Gallery, drag and drop the XY icon onto the plot.
To plot the signals on the XY visualization, drag and drop both signals onto the plot. You can specify which signal to use as the x data and which to use as the y data. For this example, use
Position as the x data and
Velocity for the y data.
You can customize the appearance of the XY visualization using the XY Settings. The line and marker colors can match the color for the signal providing the x data or for the signal that provides the y data. By default, the line uses the y -Axis signal color.
You can include multiple visualizations in a layout in the Simulation Data Inspector. For example, you can choose to use a layout with three subplots so you can see each signal on a Time Plot alongside the XY visualization.
Choose the layout with two subplots on top of a third from the Basic Layouts section of the Layouts menu. Then, plot the
Position signal in the upper right Time Plot , and plot the
Velocity signal on the bottom Time Plot .
To inspect the data, add a cursor. In the XY visualization, the vertical line of the cursor shows the x-axis value, and the horizontal line shows the y-axis value. The time corresponding to the point is displayed in the upper-right of the plot.
Move the cursor in the XY visualization along the plotted line. As you move the cursor, the next data point for the cursor to snap to is highlighted. You can also move the cursor in the XY plot using the arrow keys on your keyboard or by pausing on a point on the line and clicking the highlighted point.
When you drag a cursor in a Time Plot , the cursor in the XY visualization moves synchronously through the plotted data. The XY visualization can only have one cursor. When you add two cursors to the layout, the XY cursor moves with the left cursor in the Time Plot .
Now that you have a comprehensive visualization of the simulation data, replaying the data can help you understand the relationship between the signals. When you replay data in the Simulation Data Inspector, animated cursors sweep through the logged simulation data from the start time to the end time. Add the replay controls to the view by clicking the Show/hide replay controls button.
You can control the speed of the replay and pause at any time. By default, the Simulation Data Inspector replays data at one second per second, meaning the cursor moves through one second of data in one second of clock time. The data in this example spans 25 seconds. Slow the replay speed by clicking the arrow to the left of the label.
For more information about using replay controls, see Replay Data in the Simulation Data Inspector.