Analyze Data Using the XY Plot
This example shows how to analyze data plotted on an XY plot in the Simulation Data Inspector using trend lines.
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.
Import Data into Simulation Data Inspector
Open the Simulation Data Inspector.
The data for this example is stored in the MAT file
XYData.mat. To import the data using the UI, click Import .
In the Import dialog box, under Import from, select File. Then, enter
XYData.mat in the text box and click Import.
Alternatively, import the data programmatically using the
xyRunID = Simulink.sdi.createRun("XY signals","file","XYData.mat");
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, you need to add the visualization to the layout.
To add an XY plot to your layout, click Visualizations and layouts . Then, from Visualizations, drag the XY icon onto the subplot.
To plot signals on the XY plot, select two signals in the table and drag them onto the plot. For example, select the rows for the
Heart-Y signals, then 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 x-data and which to use as y-data in the 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.
You can modify the appearance of XY plots in the layout 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 for the signal that provides the x data or the color for 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.
Analyze XY Data Using Trend Lines
You can add a trend line to an XY plot to analyze the relationship between the x- and y-data. The trend line is most useful when the relationship can be expressed as a function. The
Heart-Y data plotted in the prior section is not well-suited for analysis with trend lines because the y-data is not well correlated with the x-data.
The example data includes x- and y-data well-suited for each type of trend line available. You can try plotting each pair of signals to see how each trend line helps you analyze the data. For example, plot the
Poly-Y signals on the XY plot:
Select the rows for both signals in the table. Hold the Shift key or the Ctrl key to select more than one signal row.
Drag the selected signals onto the plot.
In the menu that appears in the lower-right of the plot, specify which signal to use for the x-data and which to use for the y-data. In the first row, select
Poly-Xfrom the first drop-down list and select
Poly-Yfrom the second drop-down list.
To add a trend line, click Visualization Settings and select Trend line. From the Type list, select
By default, the Simulation Data Inspector computes the polynomial trend line in the form of a third-order polynomial. To see the equation for the trend line as well as information about how it fits the data, pause on the trend line. The tooltip for the trendline shows:
The names of the signals that provide the x- and y- data for the series.
The coordinates for the trend line point closest to the pointer.
The trend line equation and R-squared value.
When you use a polynomial trend line, you can specify the order of the polynomial between 2 and 6, inclusive. For example, change the order of the polynomial trend line to
2 to see how it affects the fit of the trend line. Open the visualization settings for the XY plot. Then, in the text box next to the trend line type selection, enter
When you use a second-order polynomial, the trend line does not fit the start of the data as well.
Try other trend line options to see how they fit the
Poly-Y data. You can add these types of trend line to the XY plot:
Linear: Trend line equation has the form .
Logarithmic: Trend line equation has the form . The x-data must not contain
0or negative values.
Polynomial: Trend line equation has the form , where the number of terms is determined by the specified order.
Exponential: Trend line equation has the form . The y-data must not contain
0or negative values.
Power: Trend line equation has the form . The x- and y-data must not contain
0or negative values.
Try plotting other pairs of signals in the XY plot and explore how each trend line option fits each data set.