Main Content


Turn logging on or off for a signal



Simulink.sdi.markSignalForStreaming(block,portIndex,log) marks the signal on the specified portIndex of the specified block for logging when you specify log as 'on'. To stop logging a signal, specify log as 'off'.


Simulink.sdi.markSignalForStreaming(portHandle,log) marks the signal on the port specified by portHandle for logging when you specify log as 'on'. To stop logging a signal, specify log as 'off'.


Simulink.sdi.markSignalForStreaming(lineHandle,log) marks the signal with the specified lineHandle for logging when you specify log as 'on'. To stop logging a signal, specify log as 'off'.


collapse all

This example uses the slexAircraftExample model to demonstrate how to compare the input and output signals of the control system.

Configure and Simulate the Model

The slexAircraftExample model does not log data. Load the model and mark the input and output signals for logging.

Simulink.sdi.markSignalForStreaming('slexAircraftExample/Aircraft Dynamics Model',4,'on')

Simulate the model. The data for the logged signals logs to the Simulation Data Inspector and to the workspace.

out = sim('slexAircraftExample');

Access Simulation Data

Use the Simulation Data Inspector programmatic interface to access the data. The Simulink.sdi.Run.getLatest function returns the most recently created run in the Simulation Data Inspector repository. Use the getSignalIDByIndex function to access the signal IDs for the logged signals.

aircraftRun = Simulink.sdi.Run.getLatest;

signalID1 = getSignalIDByIndex(aircraftRun,1);
signalID2 = getSignalIDByIndex(aircraftRun,2);

Specify Tolerance Values

You can specify tolerance values to use in the comparison as a property in the logged Simulink.sdi.Signal object. Use the Simulink.sdi.getSignal function to access the Signal object using the signal ID.

signal1 = Simulink.sdi.getSignal(signalID1);
signal1.AbsTol = 0.1;

Compare Signals

Use the Simulink.sdi.compareSignals function to compare the input and output signals. This example uses the isValidSignalID function to verify that both signal IDs are still valid before calling the Simulink.sdi.compareSignals function. A signal ID becomes invalid when the signal is deleted from the Simulation Data Inspector. After the comparison, check the status in the Simulink.sdi.DiffSignalResult object.

if (isValidSignalID(aircraftRun,signalID1) && isValidSignalID(aircraftRun,signalID2))
    sigDiff = Simulink.sdi.compareSignals(signalID1,signalID2);

    match = sigDiff.Status
match = 

The comparison result is out of tolerance. You can use the Simulink.sdi.view function to inspect and analyze the comparison results.

This example shows how to mark signals for logging using port handles.

Load Model and Mark Signals for Streaming

User get_param to get the port handles for the blocks with your signals of interest. Then, use the handle to mark the desired signals for logging.


% Get port handles
x1_handles = get_param('vdp/x1','PortHandles');
x1 = x1_handles.Outport(1);
x2_handles = get_param('vdp/x2','PortHandles');
x2 = x2_handles.Outport(1);

% Mark signals for streaming

Simulate Model and View Signals in the Simulation Data Inspector

Simulate the model and then open the Simulation Data Inspector to view the logged signals.



This example shows how to mark signals for logging using their line handles.

Load System and Mark Signals for Logging

Load a model and use get_param to get handles for the signals in the model. Then, use the line handles to mark signals of interest for logging.


lines = get_param('slexAircraftExample','Lines');

sig1handle = lines(1).Handle;
sig2handle = lines(2).Handle;


Simulate Model and View Signals

Simulate the model and view the signals marked for logging in the Simulation Data Inspector.



Input Arguments

collapse all

Block path for the block with the desired signal connected to one of its outports.

Example: 'slexAircraftExample/Pilot'

Index of the port connected to the signal you want to mark for streaming.

Example: 1

Logging state desired for signal.

  • 'on' –– Turn logging on for a signal.

  • 'off' –– Turn logging off for a signal.

Port handle for the source block's output port that connects to the signal.

Example: x1_handles.Outport(1)

Line handle for the signal.

Example: lines(1).Handle

Introduced in R2015b