Add trigger to signal to control display updates in the Simulation Data Inspector
Simulink.sdi.addTrigger(
adds a
rising-edge trigger using normal mode and auto-level to the sig
)Simulink.sdi.Signal
object, sig
. The trigger determines
when plots in the Simulation Data Inspector update to display new data for streaming
signals.
Simulink.sdi.addTrigger(
adds trigger to the specified signal with trigger settings specified by one or more
name-value pair arguments. For example, sig
,Name,Value
)'Mode','Normal'
configures normal
mode behavior for the trigger. Triggers in the Simulation Data Inspector behave the same as
triggers in the Scope block. For details regarding trigger types and
settings, see Scope Triggers Panel.
Add a trigger to a signal in the Simulation Data Inspector to specify criteria that determine when to update plots to display fresh data. Triggers can allow you to capture transient signal behavior and can help stabilize the display of periodic signals so you can take measurements.
Simulate the Triggers
model. Data in the model logs to the Simulation Data Inspector.
open_system('Triggers'); out = sim('Triggers');
Then, add a trigger to the Pulse
signal. Configure the trigger as a falling-edge trigger with a threshold of 0.5
.
trigRun = Simulink.sdi.getCurrentSimulationRun('Triggers'); pulseSig = getSignalsByName(trigRun,'Pulse'); Simulink.sdi.addTrigger(pulseSig,'Type','Edge','Level',0.5);
You can verify that the trigger was added and configured correctly by opening the Simulation Data Inspector using Simulink.sdi.view
and clicking the trigger icon next to the Pulse
signal to check the configuration. You can also use the Simulink.sdi.getTrigger
function to check which signal is used to generate trigger events and the trigger configuration.
[sig,trigOpts] = Simulink.sdi.getTrigger; sig.Name
ans = 'Pulse'
trigOpts
trigOpts = struct with fields:
Mode: 'Auto'
Type: 'Edge'
Position: 0.5000
Delay: 0
SourceChannelComplexity: 'Scalar'
Polarity: 'Positive'
AutoLevel: 1
Level: 0.5000
UpperLevel: 0
LowerLevel: 0
Hysteresis: 0
MinTime: 0
MaxTime: Inf
Timeout: 0
Holdoff: 0
When you do not want to use a trigger to control when the Simulation Data Inspector updates the plots with fresh data, you can remove the trigger using the Simulink.sdi.removeTrigger
function.
Simulink.sdi.removeTrigger
You can verify that the trigger was removed in the Simulation Data Inspector UI or using the Simulink.sdi.getTrigger
function. The Simulink.sdi.getTrigger
function returns an empty array of Simulink.sdi.Signal
objects when no trigger is configured in the Simulation Data Inspector.
sig = Simulink.sdi.getTrigger; size(sig)
ans = 1×2
0 0
sig
— Signal used to detect trigger eventsSimulink.sdi.Signal
objectSignal used to detect trigger events, specified as a Simulink.sdi.Signal
object.
Specify optional
comma-separated pairs of Name,Value
arguments. Name
is
the argument name and Value
is the corresponding value.
Name
must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN
.
'Type','PulseWidth','Polarity','Falling'
configures a
falling-edge, auto-leveled trigger in auto mode.'Mode'
— When display updates in response to trigger eventAuto
(default) | Normal
| Once
When display updates in response to trigger event, specified as the
comma-separated pair consisting of 'Mode'
and one of these options:
Auto
— Plots update in response to each trigger event,
and the plots update if no trigger event occurs for the duration of time range
displayed.
Normal
— Plots update in response to each trigger
event.
Once
— Plots update in response to the first trigger
event. You can manually rearm the trigger using the Simulation Data
Inspector.
Example: 'Mode','Normal'
configures the trigger to use normal
mode.
'Position'
— Where trigger event appears in plot50
(default) | numeric percentageWhere trigger event appears in plot, specified as the comma-separated pair
consisting of 'Position'
and a numeric percentage. By default, the
trigger event appears in the middle of the plot, with a position of
0.5
, or at the 50%
position within the time
span.
Example: 'Position',.3
positions the trigger event at the
30%
point within the time span.
'Type'
— Type of trigger to add to signalEdge
(default) | PulseWidth
| Transition
| Runt
| Window
| Timeout
Type of trigger to add to signal, specified as the comma-separated pair consisting
of 'Type'
and one of these options:
Edge
— Trigger when the signal crosses a
threshold.
PulseWidth
— Trigger when the signal crosses twice
between a low threshold and high threshold within a specified time.
Transition
— Trigger when the signal crosses a high
threshold and a low threshold within a specified time.
Runt
— Trigger when a signal crosses a low threshold or a
high threshold twice within a specified time.
Window
— Trigger when a signal stays within or outside a
range defined by a high threshold and a low threshold for a specified
time.
Timeout
— Trigger when a signal stays above or below a
threshold longer than a specified time.
For details regarding options for each type of trigger, see Scope Triggers Panel.
Example: 'Type','PulseWidth'
configures a pulse width
trigger.
'Polarity'
— Direction of signal value change that causes trigger eventDirection of signal value change that causes trigger event, specified as the
comma-separated pair consisting of 'Polarity'
and a valid polarity
for the trigger type.
Trigger Type | Polarity Options |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Example: 'Type','Edge','Polarity','Rising'
configures a
rising-edge trigger.
'AutoLevel'
— Whether to automatically determine trigger levelstrue
or 1
(default) | false
or 0
Whether to automatically determine trigger levels, specified as the
comma-separated pair consisting of 'AutoLevel'
and
true
or false
.
When you want to specify thresholds for the trigger, specify
'AutoLevel'
as false
.
Example: 'AutoLevel',false
configures a trigger to use a
user-specified level.
'Level'
— Threshold for trigger eventsThreshold for trigger events, specified as the comma-separated pair consisting of
'Level'
and a numeric scalar.
You can only specify the 'Level'
name-value pair when you
specify the 'Type'
name-value pair as 'Edge'
or
'Timeout'
.
Example: 'Type','Timeout','Level','0.5'
configures a timeout
trigger with a threshold of 0.5
.
'Hysteresis'
— Signal value change required around threshold to cause trigger eventSignal value change required around threshold to cause trigger event, specified as
the comma-separated pair consisting of 'Hysteresis'
and a numeric
scalar. Specifying a hysteresis for the trigger results in noise rejection for trigger
events.
You can only specify the 'Hysteresis'
name-value pair when you
specify the 'Type'
name-value pair as 'Edge'
or
'Timeout'
.
Example: 'Type','Timeout','Hysteresis','0.05'
configures a
timeout trigger that requires the signal value to change by more than
0.05
around the threshold to cause a trigger
event.
'UpperLevel'
— Upper threshold for trigger eventUpper threshold for trigger event, specified as the comma-separated pair
consisting of 'UpperLevel'
and a numeric scalar.
You can only specify the 'UpperLevel'
name-value pair when you
specify the 'Type'
name-value pair as
'PulseWidth'
, 'Transition'
,
'Runt'
, or 'Window'
.
Example: 'Type','PulseWidth','UpperLevel','0.9'
configures a
pulse width trigger with an upper threshold of 0.9
.
'LowerLevel'
— Lower threshold for trigger eventLower threshold for trigger event, specified as the comma-separated pair
consisting of 'LowerLevel'
and a numeric scalar.
You can only specify the 'LowerLevel'
name-value pair when you
specify the 'Type'
name-value pair as
'PulseWidth'
, 'Transition'
,
'Runt'
, or 'Window'
.
Example: 'Type','PulseWidth','LowerLevel','0.1'
configures a
pulse width trigger with a lower threshold of 0.1
.
'MinTime'
— Lower time limit for trigger eventLower time limit for trigger event, specified as the comma-separated pair
consisting of 'MinTime'
and a numeric scalar. You can only specify
the 'MinTime'
name-value pair when you specify the
'Type'
name-value pair as 'PulseWidth'
,
'Transition'
, 'Runt'
, or
'Window'
. The significance of the lower time limit depends on the
type of trigger.
'PulseWidth'
— Minimum pulse width for trigger
event.
'Transition'
— Minimum rise or fall time for trigger
event.
'Runt'
— Minimum pulse width for trigger event.
'Window'
— Minimum time spent within or outside value
range for trigger event.
Example: 'Type','PulseWidth','MinTime','0.1'
configures a pulse
width trigger with a minimum pulse width of 100ms
.
'MaxTime'
— Upper time limit for trigger eventUpper time limit for trigger event, specified as the comma-separated pair
consisting of 'MaxTime'
and a numeric scalar. You can only specify
the 'MaxTime'
name-value pair when you specify the
'Type'
name-value pair as 'PulseWidth'
,
'Transition'
, 'Runt'
, or
'Window'
. The significance of the upper time limit depends on the
type of trigger.
'PulseWidth'
— Maximum pulse width for trigger
event.
'Transition'
— Maximum rise or fall time for trigger
event.
'Runt'
— Maximum pulse width for trigger event.
'Window'
— Maximum time spent within or outside value
range for trigger event.
Example: 'Type','PulseWidth','MaxTime','0.5'
configures a pulse
width trigger with a maximum pulse width of 500ms
.
'Timeout'
— Time threshold for timeout triggerTime threshold for timeout trigger, specified as the comma-separated pair
consisting of 'Timeout'
and a numeric scalar.
You can only specify the 'Timeout'
name-value pair when you
specify the 'Type'
name-value pair as
'Timeout'
.
Example: 'Type','Timeout','Timeout','0.5'
configures a timeout
trigger that causes an event when a signal is above or below the value threshold for
longer than 500ms
.
'Delay'
— Trigger event offset from trigger positionTrigger event offset from trigger position, specified as the comma-separated pair
consisting of 'Delay'
and a numeric scalar.
Example: 'Type','Edge','Delay','0.1'
configures an edge trigger
where the trigger position marker is displayed 100ms
after the
trigger event.
'Holdoff'
— Minimum time between trigger eventsMinimum time between trigger events, specified as the comma-separated pair
consisting of 'Holdoff'
and a numeric scalar. After a trigger
event, the display does not update again for at least the holdoff time.
Example: 'Type','Edge','Holdoff','1'
configures an edge trigger
with a holdoff of 1s
. After a trigger event, the display does not
update for at least 1s
.
You can add a trigger to a signal and configure the trigger options using the Simulation Data Inspector UI. For details, see Control Display of Streaming Data Using Triggers.
You have a modified version of this example. Do you want to open this example with your edits?