Main Content

Simulink.sdi.getTrigger

Get signal and trigger options for trigger configured in the Simulation Data Inspector

Since R2020b

    Description

    sig = Simulink.sdi.getTrigger returns the Simulink.sdi.Signal object for the signal used to trigger display updates in the Simulation Data Inspector.

    [sig,opts] = Simulink.sdi.getTrigger returns the trigger options configured for the trigger in the Simulation Data Inspector.

    example

    Examples

    collapse all

    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: 4.6673e-62
                     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
    
    

    Output Arguments

    collapse all

    Signal used to trigger display updates in the Simulation Data Inspector, returned as a Simulink.sdi.Signal object.

    Configuration of trigger in the Simulation Data Inspector, returned as a structure that contains these fields:

    • Mode

    • Type

    • Position

    • Delay

    • SourceChannelComplexity

    • Polarity

    • AutoLevel

    • Level

    • UpperLevel

    • LowerLevel

    • Hysteresis

    • MinTime

    • MaxTime

    • Timeout

    • Holdoff

    For details on trigger configuration, see Scope Triggers Panel and Simulink.sdi.addTrigger.

    Version History

    Introduced in R2020b