Access signals in a Simulink.sdi.Run
object using signal
name
returns one or more sigs
= getSignalsByName(runObj
,name
)Simulink.sdi.Signal
objects with the name
specified by name
.
Simulink.sdi.Signal
Objects by NameYou 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;
Use the getSignalsByName
function to access the input
signal. Check the Name
property of the returned Simulink.sdi.Signal
object.
inSig = getSignalsByName(countRun,'input');
inSig.Name
ans = 'input'
The 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
. OUT
is a bus signal that contains the output signal from the counter, output
, and the counter limit signals, upper_limit
and lower_limit
, in a nested bus named LIMITBUS
.
outSig = getSignalsByName(countRun,'OUT');
Check the Name
and 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 OUT
bus.
outSig.Name
ans = 'OUT'
outChildren = outSig.Children; size(outChildren)
ans = 1×2
1 2
Because the Signal
object 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 Signal
objects.
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 OUT
bus Signal
object.
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 accessSimulink.sdi.Run
objectRun containing the signals you want to access, specified as a Simulink.sdi.Run
object.
name
— Name of signal you want to accessName 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
name
as 'slexAircraftExample.Pilot.Stick'
to
access the signal named Stick
that is the output of the
Pilot
block in the slexAircraftExample
model.
To access signals inside composite signals, specify the path to the signal through
the hierarchy of the composite signal. For example, specify name
as
'COUNTERBUS.LIMITBUS.lower_limit'
to access the
lower_limit
signal inside the bus LIMITBUS
that
is nested in the bus COUNTERBUS
.
Data Types: char
| string
sigs
— Signals matching specified nameSimulink.sdi.Signal
object | array of Simulink.sdi.Signal
objectsOne or more signals matching the specified name, returned as a Simulink.sdi.Signal
object or an array of
Simulink.sdi.Signal
objects.
getSignalIDsByName
| Simulink.sdi.compareSignals
| Simulink.sdi.deleteSignal
| Simulink.sdi.getSignal
You have a modified version of this example. Do you want to open this example with your edits?