getSignalIDsByName
Get signal IDs for signals inside Simulink.sdi.Run
object using
signal name
Since R2020a
Description
returns one or more signal IDs for signals in the sigIDs
= getSignalIDsByName(runObj
,name
)Simulink.sdi.Run
object with the specified name, name
.
Examples
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 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.
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 Simulink.sdi.Run
object.
countRun = Simulink.sdi.Run.getLatest;
Use the getSignalIDsByName
function to access the signal ID for the input
signal.
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 'ex_pulse_counter.Pulse Generator.input'
.
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: output
, upper_limit
, and lower_limit
.
To access the signal ID for the top bus, specify the signal name, OUT
.
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);
upper_limitSig.Name
ans = 'OUT.LIMITBUS.upper_limit'
Input Arguments
runObj
— Run containing signals with IDs you want to access
Simulink.sdi.Run
object
Run containing the signals with the signal IDs you want to access, specified as a
Simulink.sdi.Run
object.
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
example, specify name
as
'slexAircraftExample.Pilot.Stick'
to access the signal ID for 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 signal ID for the
lower_limit
signal inside the bus LIMITBUS
that
is nested in the bus COUNTERBUS
.
Data Types: char
| string
Output Arguments
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.
Version History
Introduced in R2020a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)