Access signals in a
Simulink.sdi.Run object using signal
Simulink.sdi.SignalObjects by Name
You can use the Simulation Data Inspector programmatic interface to access
Simulink.sdi.Signal objects that correspond to logged or imported data. Using the
getSignalsByName function, you can specify the name of the signal you want to get from a
Simulink.sdi.Run object. You can access data for individual signals and composite signals.
Create Data in the Simulation Data Inspector
This example uses a model of a pulse counter to create simulation data in the Simulation Data Inspector. The model has two input signals that define the upper and lower limit for the counter, and one input pulse signal with pulses to count. The model uses buses to send data into the
Bus Counter subsystem and out of it to an Outport block. The model is configured to log the pulse signal,
input, and the output connected to the Outport block.
Simulate the model to create a run that contains the logged data in the Simulation Data Inspector.
out = sim('ex_pulse_counter');
Access Signals in the Simulation Data Inspector
Use the Simulation Data Inspector programmatic interface to access the logged data. The
Simulink.sdi.Run.getLatest function returns the
Simulink.sdi.Run object that corresponds to the most recently created run.
countRun = Simulink.sdi.Run.getLatest;
getSignalsByName function to access the
input signal. Check the
Name property of the returned
inSig = getSignalsByName(countRun,'input'); inSig.Name
ans = 'input'
input signal is not a composite signal, so the
Children property of the
Signal object is empty.
inChildren = inSig.Children; size(inChildren)
ans = 1×2 0 0
Now, use the
getSignalsByName function to access the output signal,
OUT is a bus signal that contains the output signal from the counter,
output, and the counter limit signals,
lower_limit, in a nested bus named
outSig = getSignalsByName(countRun,'OUT');
Children properties for the returned
Signal object. The
Children property value contains two
Signal objects that correspond to the signals at the next level of hierarchy in the
ans = 'OUT'
outChildren = outSig.Children; size(outChildren)
ans = 1×2 1 2
outSig corresponds to a composite signal, you cannot plot the signal data in the Simulation Data Inspector using the
Checked property or the
plotOnSubPlot function. To plot data in the composite signal, access the individual
Access Signals Inside a Composite Signal
You can access the signals inside the
OUT bus and
LIMITBUS by indexing into the
Children property of the corresponding
Signal object. For example, you can access the
output signal from the
outChildren = outSig.Children; outputSig = outChildren(1); outputSig.Name
ans = 'OUT.output'
You can also get the
Signal object for the
output signal by specifying the path to the signal through the bus hierarchy.
outputSig = getSignalsByName(countRun,'OUT.output'); outputSig.Name
ans = 'OUT.output'
To access the
upper_limit signal, specify the full path to the signal within the bus.
upper_limitSig = getSignalsByName(countRun,'OUT.LIMITBUS.upper_limit'); upper_limitSig.Name
ans = 'OUT.LIMITBUS.upper_limit'
runObj— Run containing signals you want to access
Run containing the signals you want to access, specified as a
name— Name of signal you want to access
Name of the signal you want to access, specified as a character vector or string.
A model can use the same signal name for more than one signal. In that case, when
you want to access a specific signal, you can include the block path for the block that
produces the signal in the
name argument. For example, specify
access the signal named
Stick that is the output of the
Pilot block in the
To access signals inside composite signals, specify the path to the signal through
the hierarchy of the composite signal. For example, specify
'COUNTERBUS.LIMITBUS.lower_limit' to access the
lower_limit signal inside the bus
is nested in the bus