Main Content

Binding

Connection between app components and simulation signals and variables

Since R2024a

    Description

    Bindings represent connections between UI components in an app and model elements in a simulation. Use the Binding object to modify the behavior of the connection after you create a binding.

    Creation

    Create a binding by using the bind function.

    Properties

    expand all

    This property is read-only.

    Source object, returned as a UI component or a Signals object associated with the LoggedSignals property of a Simulation object. Together, the Source and SourceParameter properties represent the value that updates the binding destination.

    This table describes the valid source object and source parameter pairs.

    Source ObjectSource ParameterResult
    UI component, such as a Slider or Label objectProperty name, such as 'Value'When the specified property of the UI component changes (interactively or programmatically), the destination object updates.
    Signals object associated with the LoggedSignals property of a Simulation objectBlock path and port index of a logged signal, such as 'myModel/Velocity:1'When the specified signal logs data, the destination object updates.

    This property is read-only.

    Source parameter, returned as a character vector. Together, the Source and SourceParameter properties represent the value that updates the binding destination.

    This table describes the valid source object and source parameter pairs.

    Source ObjectSource ParameterResult
    UI component, such as a Slider or Label objectProperty name, such as 'Value'When the specified property of the UI component changes (interactively or programmatically), the destination object updates.
    Signals object associated with the LoggedSignals property of a Simulation objectBlock path and port index of a logged signal, such as 'MyModel/Velocity:1'When the specified signal logs data, the destination object updates.

    This property is read-only.

    Destination object, returned as a UI component or a Variables object associated with the TunableVariables property of a Simulation object. Together, the Destination and DestinationParameter properties represent the value that is updated when the binding source changes.

    This table describes the valid destination object and destination parameter pairs.

    Destination ObjectDestination ParameterResult
    UI component, such as a Slider or Label objectProperty name, such as 'Value'When the binding source changes, the specified property of the UI component updates.
    Variables object associated with the TunableVariables property of a Simulation objectVariable name, such as 'myVar:MyModel'When the binding source changes, the specified model variable updates.
    TimeScope UI component object''

    This destination can be used only when the source is a logged signal.

    When the signal logs data, the time scope updates to display the data.

    This property is read-only.

    Destination parameter, returned as a character vector. Together, the Destination and DestinationParameter properties represent the value that is updated when the binding source changes.

    This table describes the valid destination object and destination parameter pairs.

    Destination ObjectDestination ParameterResult
    UI component, such as a Slider or Label objectProperty name, such as 'Value'When the binding source changes, the specified property of the UI component updates.
    Variables object associated with the TunableVariables property of a Simulation objectVariable name, such as 'myVar:MyModel'When the binding source changes, the specified model variable updates.
    TimeScope UI component object''

    This destination can be used only when the source is a logged signal.

    When the signal logs data, the time scope updates to display the data.

    Operational state of the binding, specified as a numeric or logical 1 (true) or 0 (false).

    Examples

    collapse all

    Create a slider in a UI figure.

    fig = uifigure;
    sld = uislider(fig,Limits=[-1 0],Value=-0.8);

    Figure contains an object of type uislider.

    Create a Simulation object that represents a simulation of the bouncingBall model.

    s = simulation("bouncingBall");

    Connect the slider value to a variable in the model by creating a binding, and specify that the binding is created in a disabled state. Store the Binding object in a variable, b, so you can modify the binding after creation.

    vars = s.TunableVariables;
    varname = "K:bouncingBall";
    b = bind(sld,"Value",vars,varname,Enabled=false);

    Enable the binding by setting the Enabled property of b using dot notation.

    b.Enabled = true;

    Delete the binding using the delete function.

    delete(b)

    Version History

    Introduced in R2024a