Documentation

Simulink.sdi.Signal class

Package: Simulink.sdi

Access signal data and metadata

Description

A Simulink.sdi.Signal object provides access to signal data and metadata. The metadata includes properties for visualizing and comparing signals.

Construction

signal = Simulink.sdi.getSignal(signalID) returns a Simulink.sdi.Signal object corresponding to the signalID.

signal = runObj.getSignal(signalID) returns a Simulink.sdi.Signal object corresponding to the signalID.

signal = runObj.getSignalByIndex(index) returns a Simulink.sdi.Signal object corresponding to the signalID at the index specified by index in the Run object runObj.

Input Arguments

expand all

Numeric signal identifier for the signal.

The index of the signal within its run.

Example: 1

Properties

expand all

Signal Properties (read only)

Unique number identifying the signal.

Run identifier for the run that contains the signal.

Name of the signal.

Signal units of measure.

The signal's sample time. A value of 'Continuous' indicates a variable-step simulation.

Name of the model that produced the signal.

The path to the block that produced the signal.

Example: 'sldemo_fuelsys/Engine Gas Dynamics'

Path to the block that generates the signal including the full model hierarchy. For signals within reference models, FullBlockPath is a cell array containing the full path. For other signals, FullBlockPath is identical to BlockPath.

Index of the block port that defines the signal.

Dimensions of the matrix that contains the signal.

Indices of the signal for signals that are part of a vector or matrix.

Time and data values for the signal. For buses, Values is a struct.

Name of the high-level logging structure containing the signal for signals imported from the MATLAB workspace.

Name of the variable containing the signal's time data for signals imported from the MATLAB workspace.

Name of the array containing the signal data for signals imported from the MATLAB workspace.

Visualization Properties

Logical value indicating whether the signal is plotted on any subplot. Setting Checked to false clears the signal from all subplots. Setting Checked to true plots the signal on the active subplot.

Data Types: logical

Color of signal in plots, specified as a 1×3 RGB vector.

Example: [0 114 189]

Data Types: double

Signal line style.

  • '-' specifies a solid line style.

  • '--' specifies a dashed line style.

  • ':' specifies a dotted line style.

  • '-.' specifies a dash-dot line style.

Interpolation method used in data visualization and synchronization. 'zoh' specifies zero-order hold, and 'linear' specifies linear interpolation. For more information about the interpolation options, see How the Simulation Data Inspector Compares Data.

Comparison Properties

Positive-valued absolute tolerance of the signal used for signal and run comparisons. For more information about tolerances, see How the Simulation Data Inspector Compares Data.

Example: 0.1

Data Types: double

Positive-valued relative tolerance of the signal used for signal and run comparisons. For example, 0.1 specifies a 10% tolerance. For more information about tolerances, see How the Simulation Data Inspector Compares Data.

Example: '0.1'

Data Types: double

Method used to synchronize signal time data for comparison. For more information about the synchronization options, see How the Simulation Data Inspector Compares Data.

Methods

export Export signal object to MATLAB timeseries
getAsTall Return tall timetable with time and data values
plotOnSubPlot Plot signal on specified sub-plot

Copy Semantics

Handle. To learn how handle classes affect copy operations, see Copying Objects (MATLAB).

Examples

expand all

Use Simulink.sdi.createRun and Simulink.sdi.getSignal to create a signal object. Then, modify the signal's comparison and visualization properties.

% Configure model "slexAircraftExample" for logging and simulate
simOut = sim('slexAircraftExample','SaveOutput','on',...
                   'SaveFormat','StructureWithTime');
 
% Use Simulink.sdi.createRun to create a run and return 
% the list of signal IDs for signals contained in the run
[~,~,signalIDs] = Simulink.sdi.createRun('My Run','base',{'simOut'});

% Get the signal object corresponding to the first signal ID
signalObj = Simulink.sdi.getSignal(signalIDs(1));
 
% Define comparison and visualization properties for this signal
signalObj.syncMethod = 'intersection';
signalObj.lineColor = [1,0.4,0.6];
signalObj.lineDashed = '-';
signalObj.checked = true;

% View the signal and its parameters in the Simulation Data Inspector
Simulink.sdi.view;

This example uses the slexAircraftExample model to demonstrate the comparison of a control system's input and output signals. 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
sim('slexAircraftExample')

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

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

% Get signal IDs
signalID1 = run.getSignalIDByIndex(1);
signalID2 = run.getSignalIDByIndex(2);

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

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

    % Check whether signals match within tolerance
    match = diff.match
end
match =

  logical

   0

This example demonstrates how to access the Simulink.sdi.Run object for a run created by logging signals to the Simulation Data Inspector. From the Simulink.sdi.Run object you can get Simulink.sdi.Signal objects that you can use to view data.

% Simulate model sldemo_absbrake to create a run
sim('sldemo_fuelsys')

% Get runID for the run
runIDs = Simulink.sdi.getAllRunIDs;
runID = runIDs(end);

% Get run object for the run
run = Simulink.sdi.getRun(runID);

% Check signal count of the run
run.signalCount
ans =

  int32

   10

% Get signal objects for the signals in the run
signal1 = run.getSignalByIndex(4);
signal2 = run.getSignalByIndex(9);
signal3 = run.getSignalByIndex(10);

% Create sub-plot layout to display signals
Simulink.sdi.setSubPlotLayout(3, 1)

% Plot signals
signal1.checked = true;
signal2.plotOnSubPlot(2, 1, true);
signal3.plotOnSubPlot(3, 1, true);

%View plots in the Simulation Data Inspector
Simulink.sdi.view

You can change tolerance values on a signal-by-signal basis to evaluate the effect of a model parameter change. This example uses the slexAircraftExample model and the Simulation Data Inspector to evaluate the effect of changing the time constant for the low-pass filter following the control input.

% Load example model
load_system('slexAircraftExample')

% Mark the alpha, rad signal for streaming
Simulink.sdi.markSignalForStreaming('slexAircraftExample/Aircraft Dynamics Model', 4, 'on')

% Simulate system
sim('slexAircraftExample')

% Change input filter time constant
modelWorkspace = get_param('slexAircraftExample', 'modelworkspace');
modelWorkspace.assignin('Ts', 0.2)

% Simulate again
sim('slexAircraftExample')

% Get run data
runIDs = Simulink.sdi.getAllRunIDs;
runID1 = runIDs(end - 1);
runID2 = runIDs(end);

% Compare runs
diffRun1 = Simulink.sdi.compareRuns(runID1, runID2);

% Get signal result
sigResult1 = diffRun1.getResultByIndex(1);

% Check whether signals matched
sigResult1.match
ans =

  logical

   0

% Get signal object for sigID1
run1 = Simulink.sdi.getRun(runID1);
sigID1 = run1.getSignalIDByIndex(1);
sig1 = Simulink.sdi.getSignal(sigID1);

% Change absolute tolerance to 0.2
sig1.absTol = 0.2;

% Run the comparison again
diffRun2 = Simulink.sdi.compareRuns(runID1, runID2);
sigResult2 = diffRun2.getResultByIndex(1);

% Check the result
sigResult2.match
ans =

  logical

   1

Alternatives

Use the Simulation Data Inspector UI to view and modify signals and signal properties.

Introduced in R2012b

Was this topic helpful?