Main Content

getSignal

Class: Simulink.sdi.DatasetRef
Package: Simulink.sdi

Return Signal object

Syntax

sigObj = SDIDatasetRef.getSignal(searchArg)

Description

sigObj = SDIDatasetRef.getSignal(searchArg) returns the Simulink.sdi.Signal object corresponding to the search argument, searchArg.

Input Arguments

expand all

The search parameters to select the Simulink.sdi.Signal object. The searchArg can be a character vector or string targeting a signal name or an integer for an index-based search.

Example: 'throttle'

Example: 2

Output Arguments

expand all

The Simulink.sdi.Signal object corresponding to the search query.

Examples

expand all

This example shows how to work with the Simulink.sdi.DatasetRef object by comparing two runs of the ex_sldemo_absbrake system with different desired slip ratios.

% Simulate model ex_sldemo_absbrake to create a run of logged signals
load_system('ex_sldemo_absbrake')
sim('ex_sldemo_absbrake')

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

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

% Make a Simulink.sdi.DatasetRef object
run_DSRef = brakeRun.getDatasetRef;

% Get the names of the elements in the object
names = run_DSRef.getElementNames
names = 2x1 cell
    {'yout'}
    {'slp' }

% Get yout bus
[yout, name, index] = run_DSRef.getElement(1);

% View signals in outputs
outputs = yout.Values
outputs = struct with fields:
    Ww: [1x1 timeseries]
    Vs: [1x1 timeseries]
    Sd: [1x1 timeseries]

% Get slp signal
slp = run_DSRef.getSignal('slp');

% Plot signal
slp.Checked = 'true';
% Create another run for a different Desired relative slip
set_param('ex_sldemo_absbrake/Desired relative slip', 'Value', '0.25')
sim('ex_sldemo_absbrake')
DSR_Runs = Simulink.sdi.DatasetRef;

% Compare the results from the two runs
[matches, mismatches, diffResult] = run_DSRef.compare(DSR_Runs(2));

% Open the Simulation Data Inspector to view signals
run_DSRef.plot

Alternatives

If the signal is a top-level element in the Simulink.sdi.DatasetRef object, you can use the getElement method to get the Simulink.sdi.Signal object by index.

Introduced in R2017b