To visualize your simulation results over time, use a Scope block or Time Scope block
To connect multiple signals to a scope, drag additional signals to the scope block. An additional port is created automatically.
To specify the number of input ports:
Open a scope window.
From the toolbar, select File > Number of Input Ports > More.
Enter the number of input ports, up to 96.
You can connect signals from nonvirtual buses and arrays of buses to a
Scope block. To display the bus signals, use normal or
accelerator simulation mode. The Scope block displays each bus element signal, in
the order the elements appear in the bus, from the top to the bottom. Nested bus
elements are flattened. For example, in this model the nestedBus
signal has the const
, subSignal
, and
step
signals as elements. The subSignal
sub-bus has the chirp
and sine
signals as its
bus elements. In the Scope block, the two elements of the
subSignal
bus display between the const
and step
signals.
This example shows how to save signals to the MATLAB Workspace using the Scope block.
Using the vdp
model, turn on data logging to the workspace. You can follow the commands below, or in the Scope Configuration Parameters - Logging tab, turn on Log data to workspace.
vdp scopeConfig = get_param('vdp/Scope','ScopeConfiguration'); scopeConfig.DataLogging = true; scopeConfig.DataLoggingSaveFormat = 'Dataset'; out = sim('vdp');
In the MATLAB Command window, view the logged data from the SimulationOutput
object.
x1_data = out.ScopeData{1}.Values.Data(:,1); x1_time = out.ScopeData{1}.Values.Time; plot(x1_time,x1_data)
Use the Simulink Snapshot to pause the scope display while the simulation keeps running in the background.
Open a scope window and start the simulation.
Select Simulation > Simulink Snapshot.
The scope window status in the bottom left is Frozen, but the simulation continues to run in the background.
Interact with the paused display. For example, use measurements, copy the scope image, or zoom in or out.
To unfreeze the display, select Simulation > Simulink Snapshot again.
This example uses the model vdp to demonstrate how to copy and paste a scope image.
Add a scope block to your model.
Connect signals to scope ports. See Connect Multiple Signals to a Scope. For example, in the
vdp
model, connect the signals x1
and
x2
to a scope.
Open the scope window and run the simulation.
Select File > Copy to Clipboard.
Paste the image into a document.
By default, Copy to Clipboard saves a printer-friendly version of the scope with a white background and visible lines. If you want to paste the exact scope plot displayed, select View > Style, then select the Preserve colors for copy to clipboard check box.
This example shows how the scope plots an array of signals.
In this simple model, a Sine Wave block is connected to a scope block. The Sine Wave block outputs four signals with the amplitudes [10, 20; 30 40]
. The scope displays each sine wave in the array separately in the matrix order (1,1), (2,1), (1,2), (2,2).
This example shows the behavior of scopes in referenced models. When you use a scope in a referenced model, you see different output in the scope depending on where you started the simulation: from the top model or the scope in the referenced model.
Scope windows display simulation results for the most recently opened top model. Playback controls in scope blocks and viewers simulate the model containing that block or viewer.
This example uses the sldemo_mdlref_counter
model both as a top
model and as a referenced model from the sldemo_mdlref_basic
model.
Open the sldemo_mdlref_basic
model and double-click the
CounterA block. The sldemo_mdlref_counter
model
opens as a referenced model, as evidenced by the breadcrumb above the canvas.
Run the simulation using the main run button, then open up the ScopeA scope. The scope visualizes the data from the entire model.
If you rerun the simulation using the run button in the scope, the scope only visualizes data as if the referenced model is opened in isolation. Playback controls in scope blocks and viewers simulate the model containing that block or viewer. In this case, the referenced model input, without the top model, is zero the entire time.
If you click run from the scope, the model does not show that the model is running in the background. For the simulation status, look at the status bar in the scope.
When placed within an Enabled Subsystem block, scopes behave differently depending on the simulation mode:
Normal mode — A scope plots data when the subsystem is enabled. The display plot shows gaps when the subsystem is disabled.
External, Accelerator, and Rapid modes — A scope plots data when the subsystem is enabled. The display connects the gaps with straight lines.
You can specify signal units at a model component boundary (Subsystem
and Model blocks) using Inport and Outport
blocks. See Unit Specification in Simulink Models . You can then connect
a Scope block to an Outport block or a signal originating
from an Outport block. In this example, the Unit
property for the Out1 block was set to m/s
.
From the Scope window toolbar, select the Configuration Properties button .
In the Configuration Properties: Scope dialog box, select the Display tab.
In the Y-label box, enter a title for the y-axis
followed by (%<SignalUnits>)
. For example,
enter
Velocity (%<SignalUnits>)
Click OK or Apply.
Signal units display in the y-axis label as meters per
second (m/s
) and in the Cursor Measurements panel as
millimeters per second (mm/s
).
From the Simulink toolstrip, you can also select Debug > Information Overlays > Units. You do not have to enter (%<SignalUnits>)
in
the Y-Label property.
Get the scope properties. In the Command Window, enter
load_system('my_model') s = get_param('my_model/Scope','ScopeConfiguration');
Add a y-axis label to the first display.
s.ActiveDisplay = 1 s.YLabel = 'Velocity (%<SignalUnits>)';
You can also set the model parameter ShowPortUnits
to
'on'
. All scopes in your model, with and without
(%<SignalUnits>)
in the Y-Label
property, show units on the displays.
load_system('my_model') get_param('my_model','ShowPortUnits')
ans = off
set_param('my_model', 'ShowPortUnits','on')
ans = on
When saving simulation data from a scope with the
Dataset
format, you can find unit information in the
DataInfo
field of the timeseries object.
Scope support for signal units is only for the
Dataset
logging format and not for the legacy
logging formats Array
,
Structure
, and Structure With
Time
.
From the Scope window toolbar, select the Configuration Properties button .
In the Configuration Properties window, select the Logging tab.
Select the Log data to workspace check box. In the
text box, enter a variable name for saving simulation data. For example,
enter ScopeData
.
From the Scope window toolbar, select the run button .
In the Command Window, enter
ScopeData.getElement(1).Values.DataInfo
Package: tsdata Common Properties: Units: m/s (Simulink.SimulationData.Unit) Interpolation: linear (tsdata.interpolation)
When there are multiple ports on a scope, Simulink® ensures that each port receives data with only one unit. If you try to combine signals with different units (for example by using a Bus Creator block), Simulink returns an error.
Scopes show units depending on the number of ports and displays:
Number of ports equal to the number of displays — One port is assigned to one display with units for the port signal shown on the y-axis label.
Greater than the number of displays — One port is assigned to one display, with the last display assigned the remaining signals. Different units are shown on the last y-axis label as a comma-separated list.
From a Scope window, select the Configuration Properties button .
In the Configuration Properties dialog box, select the Main tab, and then select the Layout button.
Select the number of displays and the layout you want.
You can select more than four displays in a row or column. Click within the layout, and then drag your mouse pointer to expand the layout to a maximum of 16 rows by 16 columns.
Click to apply the selected layout to the Scope window.
In the right corner of a Scope window, click the Dock Scope button.
The Scope window is placed above the Command Window in the MATLAB® desktop.
Click the Show Scope Actions button, and then click Undock Scope.
Floating Scope | Scope | Scope Viewer