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.
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.
Use the getSignalsByName
function to access the input
signal. Check the Name
property of the returned Simulink.sdi.Signal
object.
The input
signal is not a composite signal, so the Children
property of the Signal
object is empty.
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
.
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.
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.
You can also get the Signal
object for the output
signal by specifying the path to the signal through the bus hierarchy.
To access the upper_limit
signal, specify the full path to the signal within the bus.
ans =
'OUT.LIMITBUS.upper_limit'