You can access signal IDs for signals inside a Simulink.sdi.Run
object by specifying the name of the signal for which you want the signal ID. You can use the signal ID to compare signals using the Simulink.sdi.compareSignals
function, access the Simulink.sdi.Signal
object for the signal using the Simulink.sdi.getSignal
function, or delete the signal from the Simulation Data Inspector using the Simulink.sdi.deleteSignal
function.
This example shows how to use the getSignalIDsByName
function to access a signal using its name or its block path and how to access the signal ID for a signal contained inside a bus.
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 limits 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 signal, OUT
, which is connected to the Outport block.
Simulate the model to create a run that contains the logged data in the Simulation Data Inspector.
Access Signal IDs
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. You can access the signal IDs for logged signals from the Simulink.sdi.Run
object.
Use the getSignalIDsByName
function to access the signal ID for the input
signal.
In a more complicated model, multiple signals might have the same name. In that case, using only the signal name with the getSignalIDsByName
function results in an array of signal IDs for all logged signals in the model that use that name. To avoid duplicate results, you can specify the block path and signal name together. Use dots to separate elements of the block path instead of slashes. For example, to access the signal ID for the input
signal, you could also specify the name as 'ex_pulse_counter.Pulse Generator.input'
.
Access Signal IDs for Signals Inside Composite Signals
The output logged in the ex_pulse_counter
model is a bus signal. You can access the signal ID that corresponds to the top bus signal, OUT
, the nested bus, LIMITBUS
, and the individual signals in the bus: output
, upper_limit
, and lower_limit
.
To access the signal ID for the top bus, specify the signal name, OUT
.
To access the signal ID for the nested bus, specify the path to the signal in the bus hierarchy.
To access the signal ID for one of the individual signals, specify the path to the signal in the bus hierarchy. You cannot access the signal using only the signal name. The Name
property of the Signal
object includes the bus hierarchy.
ans =
'OUT.LIMITBUS.upper_limit'