Main Content

getSignal

Get signal data from Simulation Data Inspector run

Description

sigObj = getSignal(dsr,idx) returns the Simulink.sdi.Signal object corresponding to the index idx in the Simulation Data Inspector run referenced by the Simulink.sdi.DatasetRef object dsr .

example

sigObj = getSignal(dsr,sigName) returns one or more Simulink.sdi.Signal objects corresponding to the name sigName.

Examples

collapse all

You can plot data from a Simulation Data Inspector run referenced by a Simulink.sdi.DatasetRef object in the Simulation Data Inspector programmatically.

Simulate the model ex_sldemo_absbrake to create a run of logged signals.

mdl = "ex_sldemo_absbrake";
sim(mdl)

Use the Simulink.sdi.Run.getLatest function to get the latest run.

brakeRun = Simulink.sdi.Run.getLatest;

Create a Simulink.sdi.DatasetRef object that references the run.

runID = brakeRun.ID;
DSRef = Simulink.sdi.DatasetRef(runID);

Get the names of the elements in the referenced run.

names = getElementNames(DSRef)
names = 2x1 cell
    {'yout'}
    {'slp' }

Use the getSignal function to get the yout bus. You can access the elements of the bus using the Values parameter.

yout = getSignal(DSRef,1);
outputs = yout.Values
outputs = struct with fields:
    Ww: [1x1 timeseries]
    Vs: [1x1 timeseries]
    Sd: [1x1 timeseries]

Use the getSignal function to get the slp signal. Set the Checked property to true to select the signal for plotting in the Simulation Data Inspector.

slp = getSignal(DSRef,"slp");
slp.Checked = 'true';

Open the Simulation Data Inspector to view signals.

plot(DSRef)

Input Arguments

collapse all

Run from which to get signal data, specified as a Simulink.sdi.DatasetRef object.

Index of signal to get in the Simulation Data Inspector run referenced by dsr, specified as a positive integer.

Name of signal to get in the Simulation Data Inspector run referenced by dsr, specified as a string or character array.

Alternatives

To return a copy of the signal data to the workspace, you can use the getElement function.

Version History

Introduced in R2017b