Main Content

Visualize Simulation Data on an XY Plot

This example shows how to plot data on an XY plot in the Simulation Data Inspector and use the replay controls to analyze relationships among plotted signals. You run two simulations of the model ex_sldemo_bounce and analyze the relationship between the position and velocity for a bouncing ball.

The XY plot used in this example is also available in the Record block and the XY Graph block. When you use the XY plot in the Record block and the XY Graph block, you add the visualization and configure the appearance using the toolstrip. You plot data on the XY plot the same way shown in this example.

Simulate Model

Open the model ex_sldemo_bounce, which simulates the dynamics of a bouncing ball.

open_system("ex_sldemo_bounce")

Because the model is configured to log output data, the position and velocity signals connected to the Outport blocks log to the workspace and the Simulation Data Inspector.

To simulate the model, click Run. Then, under Review Results, click Data Inspector to open the Simulation Data Inspector.

Alternatively, you can simulate the model and open the Simulation Data Inspector programmatically.

out = sim("ex_sldemo_bounce");
Simulink.sdi.view

Plot Data on XY Plot

By default, the Simulation Data Inspector uses time plots for each subplot in the layout. To plot the data on an XY plot, add the visualization to the layout. Click Visualizations and layouts, then drag the XY icon onto the subplot.

To plot the signals on the XY plot, select the rows for both the signals in the table and drag them onto the plot. Hold the Shift key or the Ctrl key to select more than one signal row in the table.

Specify which signal to use as the x data and which to use as the y data in the series menu that appears in the lower-right of the plot. Use the first drop-down list to select the signal that provides the x data, and use the second drop-down list to select the signal that provides the y-data. To swap the current x and y data selections, click the Swap button between the drop-down lists.

For this example, use Position as the x data and Velocity for the y data.

You can modify the appearance of the XY plot using the Visualization Settings. To access the Visualization Settings for the XY plot, click Visualization Settings.

The line and marker colors can match the color of the signal that provides the x data or the signal that provides the y data. By default, the line and markers both use the y-axis signal color. Specified settings apply for all XY plots in the layout.

You can also change the limits of the x-axis and y-axis from the Visualization Settings. To change the limits, first, clear Autoscale. Then, enter new values for the x and y limits. These limits apply to the currently selected XY subplot. By default, Autoscale is selected, which performs a fit-to-view on the XY subplot.

Add Time Plots and Inspect Data

You can include multiple visualizations in a layout in the Simulation Data Inspector, Record block, or XY Graph block. For example, change to a layout with three subplots so you can see each signal on a time plot alongside the XY plot.

To change the subplot layout, click Visualizations and layouts. Then, in the Basic Layouts section, select the layout with two subplots on top of a third subplot.

Plot the Position signal on the upper-right time plot, and plot the Velocity signal on the bottom time plot. To plot a signal on a time plot, select the subplot where you want to plot the signal, then select the check box next to the signal you want to plot.

To inspect the data, add a cursor. In the XY plot, the vertical line of the cursor shows the x-axis value, and the horizontal line shows the y-axis value. The time that corresponds to the point is displayed in the upper-right of the plot.

Move the cursor in the XY plot along the plotted line. 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 the cursor in a time plot, the cursor in the XY plot moves synchronously through the plotted data. The XY plot 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.

Replay Data

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 Show/hide replay controls.

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.

Analyze Data from Multiple Simulations

To analyze how changes in simulation parameters affect the data, you can plot multiple series on an XY plot. Simulate the model again using a higher initial velocity for the ball.

Using the Simulink® Editor or the MATLAB™ Command Window, change the Initial value parameter of the Initial Velocity block to 25. Then, 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. To adjust the zoom level for the signals from the new run, click Fit to View.

Drag the first run from the archive into the work area. Then, use the run actions menu to copy the plotted signal selection from the current run to the first run.

To copy the plotted signal selection from the current run, click the three dots on the right of the row for the current run. Then, under Plotted signal selection, select Copy.

To plot data from the first run, paste the plotted signal selection onto the run. Click the three dots on the right of the row for the first run. Then, under Plotted signal selection, select Paste.

The signals in both runs have the same names and the same signal colors. Change the colors for the signals in the first run.

  1. Click the representation of the line in the table.

  2. Select a new color.

  3. Click Set.

The signals in both runs also have the same name. To determine which run contains a plotted signal, you can use the tooltip in the legend.

You can also rename the signals. For example, rename the signals in the first run to Position-1 and Velocity - 1. To rename a signal, double-click the name in the table and enter a new name.

When you add multiple series to an XY plot, each series gets a cursor. All cursors on the XY plot move synchronously, so all signal values displayed on the cursors correspond to the same time.

You can manage the signals plotted on an XY plot using the subplot context menu. Right-click the XY plot and select Show plotted signals. Using the series menu, you can remove series from the plot or modify which signals provide the x-data and y-data for each series.

See Also

Blocks

Tools

Related Topics