Common Scope Block Tasks

To visualize your simulation results over time, use a Scope block or Time Scope block

Connect Multiple Signals to a Scope

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:

  1. Open a scope window.

  2. From the toolbar, select File > Number of Input Ports > More.

  3. Enter the number of input ports, up to 96.

Signals from Nonvirtual Buses and Arrays of Buses

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.

Save Simulation Data Using Scope Block

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)

Pause Display While Running

Use the Simulink Snapshot to pause the scope display while the simulation keeps running in the background.

  1. Open a scope window and start the simulation.

  2. Select Simulation > Simulink Snapshot.

    The scope window status in the bottom left is Frozen, but the simulation continues to run in the background.

  3. Interact with the paused display. For example, use measurements, copy the scope image, or zoom in or out.

  4. To unfreeze the display, select Simulation > Simulink Snapshot again.

Copy Scope Image

This example uses the model vdp to demonstrate how to copy and paste a scope image.

  1. Add a scope block to your model.

  2. 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.

  3. Open the scope window and run the simulation.

  4. Select File > Copy to Clipboard.

  5. 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.

Plot an Array of Signals

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).

Scopes in Referenced Models

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.

Note

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.

Note

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.

Scopes Within an Enabled Subsystem

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.

Show Signal Units on a Scope Display

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.

Show Units on a Scope Display

  1. From the Scope window toolbar, select the Configuration Properties button .

  2. In the Configuration Properties: Scope dialog box, select the Display tab.

  3. In the Y-label box, enter a title for the y-axis followed by (%<SignalUnits>). For example, enter

    Velocity (%<SignalUnits>)
    
  4. 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 > Ports Units. You do not have to enter (%<SignalUnits>) in the Y-Label property.

Show Units on a Scope Display Programmatically

  1. Get the scope properties. In the Command Window, enter

    load_system('my_model')
    s = get_param('my_model/Scope','ScopeConfiguration');
    
  2. 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

Determine Units from a Logged Data Object

When saving simulation data from a scope with the Dataset format, you can find unit information in the DataInfo field of the timeseries object.

Note

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.

  1. From the Scope window toolbar, select the Configuration Properties button .

  2. In the Configuration Properties window, select the Logging tab.

  3. Select the Log data to workspace check box. In the text box, enter a variable name for saving simulation data. For example, enter ScopeData.

  4. From the Scope window toolbar, select the run button .

  5. In the Command Window, enter

    ScopeData.getElement(1).Values.DataInfo
    Package: tsdata
    Common Properties:
                 Units: m/s (Simulink.SimulationData.Unit)
         Interpolation: linear (tsdata.interpolation)
    

Connect Signals with Different Units to a Scope

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.

Select Number of Displays and Layout

  1. From a Scope window, select the Configuration Properties button .

  2. In the Configuration Properties dialog box, select the Main tab, and then select the Layout button.

  3. 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.

  4. Click to apply the selected layout to the Scope window.

Dock and Undock Scope Window to MATLAB Desktop

  1. 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.

  2. Click the Show Scope Actions button, and then click Undock Scope.

See Also

| |

Related Topics