getSignalsByName
Description
returns one or more sigs
= getSignalsByName(runObj
,name
)Simulink.sdi.Signal
objects with the name
specified by name
.
Examples
Access Simulink.sdi.Signal
Objects by Name
You 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'
Input Arguments
runObj
— Run containing signals you want to access
Simulink.sdi.Run
object
Run containing the signals you want to access, specified as a Simulink.sdi.Run
object.
name
— Name of signal you want to access
character vector | string
Name 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
Output Arguments
sigs
— Signals matching specified name
Simulink.sdi.Signal
object | array of Simulink.sdi.Signal
objects
One or more signals matching the specified name, returned as a Simulink.sdi.Signal
object or an array of
Simulink.sdi.Signal
objects.
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)