Main Content

plot

Plot data in Simulation Data Inspector

Since R2019b

  • Simulation Data Inspector

Description

Use the plot function to plot data contained in objects such as Dataset, SimulationOutput, or Signal objects in the Simulation Data Inspector.

For more information about interactively plotting data in the Simulation Data Inspector and customizing the plot appearance, see Create Plots Using the Simulation Data Inspector.

To create a 2-D line plot in a MATLAB® figure, see plot.

example

plot(obj) plots the simulation results in the object obj in the Simulation Data Inspector and opens the Simulation Data Inspector. You can use the plot function to plot data and simulation results stored in an object such as:

When the input object contains fewer than eight signals, the Simulation Data Inspector layout changes to 1-by-n, where n is the number of signals, and each subplot displays one signal. When the simulation results contain more than eight signals to plot, the Simulation Data Inspector layout changes to 1-by-1, and the plot displays the first signal.

plot(ds,viewer) displays data contained in a Simulink.SimulationData.Dataset or Simulink.SimulationData.DatasetRef object in the Simulation Data Inspector or Signal Preview window according to the value specified for viewer.

runObj = plot(___) returns the Simulink.sdi.Run object that corresponds to the plotted data.

Examples

collapse all

The model ex_vdp_simout_plot is configured to log signals, outputs, and states and return all logged data as a single simulation output. You can use the plot function to plot the simulation results in the Simulation Data Inspector.

Simulate the model. The model logs data using the Dataset format, so all the logged data streams to the Simulation Data Inspector during simulation.

mdl = "ex_vdp_simout_plot";
open_system(mdl)
out = sim(mdl);

Use the plot function to plot all the simulation results in the Simulation Data Inspector. The Simulation Data Inspector updates to a 1-by-8 layout and plots one signal on each subplot.

plot(out)

All simulation results plotted in the Simulation Data Inspector

You can also use the plot function to plot data for a single signal or a subset of the simulation results. When you plot the data for a single signal, the Simulation Data Inspector always imports the data for the signal into a new run.

The Simulink.SimulationOutput object contains a property for each logging variable. Access the signal logging data in the property logsout.

logsout = out.logsout
logsout = 
Simulink.SimulationData.Dataset 'logsout' with 4 elements

                         Name  BlockPath                  
                         ____  __________________________ 
    1  [1x1 Signal]      ''    ex_vdp_simout_plot/Fcn    
    2  [1x1 Signal]      ''    ex_vdp_simout_plot/Mu     
    3  [1x1 Signal]      ''    ex_vdp_simout_plot/Product
    4  [1x1 Signal]      ''    ex_vdp_simout_plot/Sum    

  - Use braces { } to access, modify, or add elements using index.

Use the get function for the Dataset object to access the data for the first element, which contains the data for a single logged signal.

sig1 = get(logsout,1);

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

plot(sig1)

A single signal plotted in a new run in the Simulation Data Inspector

Create two timeseries objects.

ts1 = timeseries([0;20],[0;10]);  
ts2 = timeseries([0;40],[0;10]);  

Create a Dataset object. Then, add the timeseries objects to the Dataset object.

ds = Simulink.SimulationData.Dataset;
ds = addElement(ds,ts1,"timeseries1");
ds = addElement(ds,ts2,"timeseries2");

Plot the Dataset object in the Simulation Data Inspector.

plot(ds)

Input Arguments

collapse all

Data to plot in Simulation Data Inspector, specified as one of these objects:

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 the SimulationOutput object does not correspond to a run in the Simulation Data Inspector, the plot function imports the data into a new run.

When you use the plot function to plot a single signal, the plot function always imports the data for the signal into a new run.

You can also use the Simulink.sdi.plot function to programmatically plot any of the listed objects as well as timeseries and timetable data.

Example: plot(out) plots the contents of the Simulink.SimulationOutput object out in the Simulation Data Inspector and opens the Simulation Data Inspector.

Data to plot in specified visualization tool, specified as a Simulink.SimulationData.Dataset object or a Simulink.SimulationData.Datasetref object.

Viewer used to plot data, specified as "datainspector" or "preview". When you do not specify the viewer input, the plot function plots data in the Simulation Data Inspector.

Output Arguments

collapse all

Run that corresponds to the plotted data, returned as a Simulink.sdi.Run object.

Version History

Introduced in R2019b

expand all