Get signal IDs for signals inside
Simulink.sdi.Run object using
Get Signal IDs by Signal Name
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
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.
out = sim('ex_pulse_counter');
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
countRun = Simulink.sdi.Run.getLatest;
getSignalIDsByName function to access the signal ID for the
inSigID = getSignalIDsByName(countRun,'input');
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
inSigID = getSignalIDsByName(countRun,'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:
To access the signal ID for the top bus, specify the signal name,
OUTSigID = getSignalIDsByName(countRun,'OUT');
To access the signal ID for the nested bus, specify the path to the signal in the bus hierarchy.
LIMITBUSSigID = getSignalIDsByName(countRun,'OUT.LIMITBUS');
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.
upper_limitSigID = getSignalIDsByName(countRun,'OUT.LIMITBUS.upper_limit');
upper_limitSig = Simulink.sdi.getSignal(upper_limitSigID);
ans = 'OUT.LIMITBUS.upper_limit'
runObj — Run containing signals with IDs you want to access
Run containing the signals with the signal IDs you want to access, specified as a
name — Name of signal with ID you want to access
character vector | string
Name of the signal with the signal ID 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 the signal ID for a specific signal, you can include the block path
for the block that produces the signal in the
name argument. For
'slexAircraftExample.Pilot.Stick' to access the signal ID for the
Stick that is the output of the
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 signal ID for the
lower_limit signal inside the bus
is nested in the bus
sigIDs — Signal IDs for signals with specified name
scalar | array
One or more signal IDs for signals with the specified name, returned as a scalar or array.
Introduced in R2020a