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 Layout menu and click Edit View to open the Visualization Gallery.
From the Visualization Gallery, drag and drop the XY icon onto the plot.
To plot the signals on the XY visualization, select both signals then drag and drop them 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 by opening the Visualization Settings. The line and marker colors match the color of the signal that provides the x data or 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.
In the Layout menu, choose the layout with two subplots on top of a third from the Basic Layouts section. 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.
To analyze how changes in simulation parameters affect the data, you can plot multiple series on an XY visualization. In the model or MATLAB™ Command Window, change the Initial value parameter of the Initial Velocity block to
25 and simulate the model.
set_param('ex_sldemo_bounce/Initial Velocity','Value','25') sim('ex_sldemo_bounce');
The Simulation Data Inspector moves the first run to the archive and transfers the view to the new run. Drag the first run from the archive into the work area.
The signals in both runs have the same names and the same signal colors. Before you add data from the first run to the plots, change the signal names and colors. For example, you can rename the signals from the first run
Velocity-1. To modify a signal color, click the line representation in the table, select a new color, and click Set. To modify the signal names, double-click the name in the table and enter the new name.
Now, add the data from the first run to the plots in the layout. Plot the signals from the first run on the time plots. To add another series to the XY visualization, select both signals and drag them onto the plot. The connection dialog shows the first series that is already plotted. Select the
Position-1 signal as the x-data for series 2 and
Velocity-1 as the series 2 y-data. Then click OK.
When you add multiple series to an XY visualization, each series gets a cursor. All cursors on the XY visualization move synchronously, so all signal values displayed on the cursors correspond to the same time.
You can manage the signals plotted on an XY visualization using the context menu. Right-click the XY plot area and select
Show plotted signals to bring up the connection dialog. From the connection dialog, you can remove series from the plot or modify the signals that provide the x-data and y-data for each series.