plot

Plot simulation output data in the Simulation Data Inspector

Description

example

plot(simOutObj) plots the simulation output data in the simulation output object, simOutObj, in the Simulation Data Inspector and opens the Simulation Data Inspector so you can view the plotted simulation output data. You can use the plot function to plot simulation results stored in these simulation output objects:

These simulation output objects also have plot functions that plot the data in and then open the Simulation Data Inspector:

When a simulation output object contains fewer than eight signals to plot, the Simulation Data Inspector layout changes to 1-by-n, where n is the number of signals to plot, and plots one signal on each subplot. When the simulation output object contains more than eight signals to plot, the Simulation Data Inspector layout changes to 1-by-1 and plots the first signal in the simulation output object.

When some or all of the data in a Simulink.SimulationOutput object is in a Simulation Data Inspector run, the plot function opens the Simulation Data Inspector and plots all the signals in the run. When you do not select the Record logged workspace data in Simulation Data Inspector option, logged states data does not appear in the Simulation Data Inspector and is not plotted. When the data does not correspond to a run in the Simulation Data Inspector, the plot function imports the data to a new run. When you use the plot function to plot a single signal, the plot function always imports the data for the signal to a new run.

runObj = plot(simOutObj) returns the Simulink.sdi.Run object corresponding to the plotted data.

Examples

collapse all

When you create a new model in R2019a or later, the default model configuration saves simulation outputs in a single output. The single simulation output is a Simulink.SimulationOutput object that contains one or more types of other simulation output objects, depending on the kinds of data you log. This example uses a model configured to save a single simulation output and shows how to access each type of logged data and use the plot function to plot the data in the Simulation Data Inspector and then open the Simulation Data Inspector so you can view the data.

The ex_vdp_simout_plot model used in this example is configured to log signals, outputs, and states and return all logged data in a single simulation output. This example shows how to access each type of logged data and use the plot function to plot the data in the Simulation Data Inspector. To generate the SimulationOutput object containing all the logged data, simulate the model.

open_system('ex_vdp_simout_plot.slx')
out = sim('ex_vdp_simout_plot.slx');

Plot Data in a SimulationOutput Object

You can pass the single simulation output, stored in a Simulink.SimulationOutput object, to the plot function to plot and view the data in the Simulation Data Inspector. When you plot data in a SimulationOutput object that corresponds to a run in the Simulation Data Inspector, data in the object that also logs to the Simulation Data Inspector is plotted. The model logs four signals, data for the two Outport blocks, and states. Signal and output data always log to the Simulation Data Inspector, and states data only appears in the Simulation Data Inspector when you select the Record logged workspace data in Simulation Data Inspector option, which is not selected for this model. When you use the plot function to plot the data, the Simulation Data Inspector layout updates to a 1-by-6 layout and plots one signal on each subplot.

plot(out)

Plot Logged States Data

When you do not log states data to the Simulation Data Inspector, you can use the plot function to import and plot the states data. The model logs data for two states, x1 and x2. The states data is saved in a Simulink.SimulationData.Dataset object, xout, with one element corresponding to each Simulink.SimulationData.State object. You can use the plot function to plot the data for both signals by plotting xout, or you can plot data for a single state.

Access the Dataset object, xout, using the get function for the SimulationOutput object. You can also access the logged output and signal data using the get function.

xout = get(out,'xout');

When you plot the data for both states in the Dataset object, the Simulation Data Inspector layout changes to 1-by-2 and plots the data for each state on one subplot.

plot(xout)

Plot Data for a Single Signal

When you plot the data for a single signal, the Simulation Data Inspector always imports the data for the signal to a new run. Use the get function for the SimulationOutput object to access the signal logging Dataset object, logsout.

logsout = get(out,'logsout');

Then, use the get function for the Dataset object to access the data for the first element.

sig1 = get(logsout,1);

When you plot the data for the signal, the Simulation Data Inspector imports the signal to a new run, updates the layout to 1-by-1, and plots the signal.

plot(sig1)

Input Arguments

collapse all

Simulation output object containing data you want to plot and view in the Simulation Data Inspector. This plot function supports these simulation output objects:

Example: plot(out)

Output Arguments

collapse all

Simulink.sdi.Run object corresponding to the plotted data.

Introduced in R2019b