Simulink.sdi.markSignalForStreaming

Turn logging on or off for a signal

Description

example

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

example

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

example

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

Examples

collapse all

This example uses the slexAircraftExample model to demonstrate the comparison of the input and output signals for a control system. The example marks the signals for streaming then gets the run object for a simulation run. Signal IDs from the run object specify the signals to be compared.

% Load model slexAircraftExample and mark signals for streaming
load_system('slexAircraftExample')
Simulink.sdi.markSignalForStreaming('slexAircraftExample/Pilot',1,'on')
Simulink.sdi.markSignalForStreaming('slexAircraftExample/Aircraft Dynamics Model',4,'on')

% Simulate model slexAircraftExample
out = sim('slexAircraftExample');

% Get run IDs for most recent run
allIDs = Simulink.sdi.getAllRunIDs;
runID = allIDs(end);

% Get Run object
aircraftRun = Simulink.sdi.getRun(runID);

% Get signal IDs
signalID1 = getSignalIDByIndex(aircraftRun,1);
signalID2 = getSignalIDByIndex(aircraftRun,2);

if (isValidSignalID(aircraftRun,signalID1))
    % Change signal tolerance
    signal1 = Simulink.sdi.getSignal(signalID1);
    signal1.AbsTol = 0.1;
end

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

    % Check whether signal result status
    match = sigDiff.Status
end
match = 
OutOfTolerance

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.

load_system('vdp')

% 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
Simulink.sdi.markSignalForStreaming(x1,'on');
Simulink.sdi.markSignalForStreaming(x2,'on');

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.

sim('vdp');

Simulink.sdi.view

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.

load_system('slexAircraftExample')

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

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

Simulink.sdi.markSignalForStreaming(sig1handle,'on')
Simulink.sdi.markSignalForStreaming(sig2handle,'on')

Simulate Model and View Signals

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

sim('slexAircraftExample')

Simulink.sdi.view

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