Main Content

Probe

Output block variables as signals during simulation

Since R2020a

  • Probe block

Libraries:
Simscape / Utilities

Description

The Probe block lets you select variables from another block in the model and output them as Simulink® signals. The following rules apply:

  • The selected block must be at the same level of the model hierarchy as the Probe block.

  • After selecting the block, select the variables to probe. The context menu on the model canvas or the Probe block Property Inspector contains all the externally accessible block variables, regardless of whether they are exposed in the Initial Targets section of the block dialog box.

    Externally accessible variables include:

    • Component variables, including event variables

    • Domain Across variables at each of the nodes

    • Inputs

    • Outputs

    • Intermediates

    • Mode chart elements

    These members must be declared with the ExternalAccess attribute value of either modify or observe. Essentially, these are the same variables that you can see in the simulation data log or instrumentation table.

  • In case of conditional visibility, if a variable is active only in a subset of block parameterizations, such a variable is always available for probing, regardless of whether it is active in the current block configuration.

  • In case of conditional declaration, variables are not available for probing, regardless of whether the conditional branch is active in the current block configuration. For composite components, this limitation includes all the externally accessible variables of conditionally declared components.

  • Each of the selected variables is output as a separate signal.

  • The output signal unit matches the nominal unit of the variable. For more information, see Specify Nominal Value-Unit Pairs for a Model and Units in Simulink.

  • The Probe block outputs Simulink signals. Therefore, you can connect it directly to Simulink blocks, like scopes or buses.

  • You can attach (bind) a Probe block to only one block at a time. However, you can bind multiple Probe blocks to the same block in the model at the same time.

Working with the Block on the Model Canvas

To bind variables to a Probe block:

  1. Add the Probe block to a model at the desired level.

  2. Double-click the Probe block to start the binding process.

  3. Select a Simscape™ block at the same level of the model hierarchy.

  4. From a context menu containing all the block variables available for probing, select the variables to output. For example, if you selected a Rotational Electromechanical Converter block, the available variables include current, voltage, torque, and angular velocity, as well as voltage at each of the electrical ports and the rotational velocity at ports C and R.

    Selecting variables to probe on the model canvas

    To facilitate working with long lists of variables, the context menu has a Type to Filter field at the top. Type in this field to display only the variables that contain the filter string in their name or id.

    You can also use the top check box, located just below the Type to Filter field, to select all or unselect all the currently listed variables.

  5. To finish the binding process, click the X in the upper-right corner of the model canvas.

  6. For each selected variable, the Probe block acquires an additional output port, with the port name matching the variable ID. (In this example, the port names are i and w.) Connect these ports to scopes or other blocks from the Simulink Sinks library to view the signal values during simulation.

    Block diagram with Probe outputs connected to scopes

    Scopes showing simulation results

To bind a Probe block to a different block in the model, or to change the selected variables, double-click the Probe block again and repeat the binding process. When binding to a different block, if the new block has variables with the same IDs as the ones previously bound, these variables are automatically selected again.

If you copy a Probe block together with the block that it is bound to, the connection is preserved and the same variables are automatically selected in the new pair.

Use Property Inspector to Specify Variables to Probe and Set Variable Configuration

Instead of selecting variables to probe directly on the model canvas, you can use the Property Inspector to select the variables, set the units of the output signal, and customize the output port labels of the Probe block:

  1. The binding process is the same as in the previous example, Working with the Block on the Model Canvas.

    Double-click the Probe block to start the binding process. Select a Simscape block at the same level of the model hierarchy, for example, the Rotational Electromechanical Converter block. To finish the binding process, click the X in the upper-right corner of the model canvas.

  2. Select variables to probe by using the Property Inspector. To open the Property Inspector, select the Probe block and press Ctrl+Shift+I or, on the Modeling tab of the model toolstrip, in the Design section, select Property Inspector.

    The Property Inspector window contains the name of the block being probed, in this case Rotational Electromechanical Converter, and a table of all the block variables that can be probed. Once you select a variable to probe, you can expand it in the table to view the associated port label and unit.

    Selecting variables to probe in the Property Inspector

  3. For each selected variable, the Probe block acquires an additional output port, with the port name matching the port label in the Property Inspector. Initially, the port label matches the variable name, but you can edit it by double-clicking its name in the Property Inspector, in the cell to the right of Port Label. You can also click in the cell to the right of Unit and select a different output unit for the output signal from the drop-down list.

  4. Connect the Probe block output ports to scopes or other blocks from the Simulink Sinks library to view the signal values during simulation.

    Block diagram with Probe outputs connected to scopes

    Scopes showing simulation results

Command Line Workflow

Instead of the interactive workflow on the model canvas, you can bind a Probe block and select variables by using these commands:

  • simscape.probe.setBoundBlock(probeBlock, boundBlock) — Binds probeBlock to boundBlock. probeBlock must be a valid full block path or a handle to a Probe block. boundBlock must be a valid full block path or a handle to another block at the same level of the model hierarchy as probeBlock. The command does not check whether boundBlock is a Simscape block or whether it has variables to probe.

    simscape.probe.setBoundBlock(probeBlock, []) returns the Probe block to the unbound state. Does not affect the selected variables.

  • simscape.probe.setVariables(probeBlock, variables) — Selects variables for the probeBlock to output. probeBlock must be a valid full block path or a handle to a Probe block. variables must be a character vector, cell array of character vectors, or string array that specifies the variables. The character vectors or strings must be unique variable identifiers, lexicographically sorted. The command does not check whether the currently selected boundBlock contains these variables.

    Instead of lexicographically sorting the variables, you can use this syntax:

    I = simscape.probe.setVariables(probeBlock, variables, 'Sort', true)

    The command then sorts the variables before applying them to probeBlock. Variable identifiers must still be unique. I returns the order in which the sorted variables appear as ports on the Probe block.

The programmatic equivalent of the interactive binding and variable selection shown in the example in Working with the Block on the Model Canvas is:

simscape.probe.setBoundBlock('PermanentMagnetDCMotor/DC Motor/Probe','PermanentMagnetDCMotor/DC Motor/Rotational Electromechanical Converter');
simscape.probe.setVariables('PermanentMagnetDCMotor/DC Motor/Probe',["i", "w"]);

As a result, the Probe block also has two output ports, i and w, bound to the Current : i and Angular velocity : w variables of the Rotational Electromechanical Converter block, respectively.

If you supply unsorted variables, the command returns the sorted order:

I = simscape.probe.setVariables('PermanentMagnetDCMotor/DC Motor/Probe', ["w", "i"], 'Sort', true)
I =

     2     1

In this example, the second variable, i, appears as the first port on the Probe block, followed by the first variable, w.

You can use the simscape.probe.getBoundBlock(probeBlock) and simscape.probe.getVariables(probeBlock) commands, where probeBlock is a valid full block path or a handle to a Probe block, to return its bound block and variables, respectively.

You can also use the simscape.probe.defaultVariableTable, simscape.probe.setVariableTable, and simscape.probe.getVariableTable functions to construct VaraibleTable objects and attach them to a Probe block.

Examples

Ports

Output

expand all

Outputs the values of one selected variable during simulation as a Simulink signal. The port name matches the name of selected variable. The output signal unit matches the unit of the variable. You can modify the port label and change the unit of the output signal by using the Property Inspector.

If you select more than one variable, the block acquires additional output ports.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced in R2020a

expand all