Main Content


Message between lifelines in interaction

Since R2024a


    A Message object represents a communication between two lifelines of an interaction. On the sequence diagram representing the interaction, a message is shown as an arrow. Messages have labels that can describe the communication occurrence either formally or informally. A message corresponds to a connector connecting ports of two components in an architecture model.

    An informal message label is written in natural language. A formal message label is in the form of trigger[constraint] where trigger represents the identifying event for this message, and constraint represents additional expressions that are expected to be true when this message occurs.

    • For signal-based communication, a trigger is also called an edge and can described in the format direction(signal [+|-] value). You can enter a condition that specifies a triggering edge with a direction and an expression. The direction can be:

      • rising — The edge expression is rising from strictly below zero to a value equal to or greater than zero.

      • falling — The edge expression is falling from strictly above zero.

      • crossing — The edge expression is either rising or falling past zero.

    • For message-based communication, a trigger can be described simply by using the name of the input message port, and represents the arrival of a message.

    • For both signal and message-based communication, a constraint expression in square brackets on the message label is an optional MATLAB® Boolean expression involving the names of the inputs to the destination lifeline.


    Access Message objects via the RootFragment property of the corresponding systemcomposer.interaction.Interaction object. Iterate over the root fragment to inspect the systemcomposer.interaction.MessageEvent objects within the fragments. Access the Message property of the message event to inspect the corresponding Message object.


    expand all

    Message type, specified as one of the following options:

    • "Signal" for signal-based communication.

    • "Message" for Simulink® message-based communication.

    Data Types: string

    Message label, specified as a string.

    Data Types: string

    Start of message, specified as a systemcomposer.interaction.MessageEvent object.

    End of message, specified as a systemcomposer.interaction.MessageEvent object.

    Connectors represented by message, specified as an array of systemcomposer.arch.Connector or systemcomposer.arch.PhysicalConnector objects.

    Universal unique identifier, specified as a character vector.

    Example: '91d5de2c-b14c-4c76-a5d6-5dd0037c52df'

    Data Types: char


    collapse all

    This example shows how to use read-only API workflows to navigate sequence diagrams in System Composer™ and display information about each of the elements.

    Open Traffic Light Example

    Open the traffic light example architecture model so that you can inspect the sequence diagrams visually and confirm the programmatic outputs.

    model = systemcomposer.openModel("TLExample");

    On the System Composer toolstrip, navigate to Modeling > Sequence Diagram to view the sequence diagrams associated with the model.

    The press detection sequence diagram in the views gallery of the top model.

    Programmatically Navigate Sequence Diagram

    Collect the sequence diagrams represented by interactions that contain specific interactions of elements in the model.

    interactions = model.getInteractions;

    For the first interaction, extract the name of the sequence diagram.

    disp("The first sequence diagram is called " + interactions(1).Name + ".")
    The first sequence diagram is called SignalSequence.

    For this sequence diagram, display each lifeline and the component the lifeline represents.

    for i = 1:length(interactions(1).Lifelines)
        disp("The " + interactions(1).Lifelines(i).Name + ...
        " lifeline represents the " + ...
        interactions(1).Lifelines(i).RelatedElements.Name + ...
        " component.")
    The ped lamp lifeline represents the ped lamp component.
    The lampController lifeline represents the lampController component.
    The poller lifeline represents the poller component.
    The source lifeline represents the source component.

    Now, display the contents of one message in the root fragment.

    disp("The sequence diagram message starting at the " + ...
        interactions(1).RootFragment.Operands.Fragments(1).Name + ...
        " message end is of type " + ...
        string(interactions(1).RootFragment.Operands.Fragments(1).Message.Type) + ...
        " and the message label is " + ...
        interactions(1).RootFragment.Operands.Fragments(1).Message.Condition + ".")
    The sequence diagram message starting at the switchout message end is of type Signal and the message label is rising(sw-1).

    Use Iterator Utility to Step Through Sequence Diagram

    Step through the Inhibit sequence diagram using the Iterator utility.

    interaction = model.getInteraction('Inhibit');

    Inhibit sequence diagram from the top model.

    Display the annotation from the interaction.

    When inhibit is true, it means pedestrian crossing is not controlled by a walk signal on this intersection.

    Use an iterator to navigate through all elements of a sequence diagram before extracting their properties.

    iterator = systemcomposer.interaction.Iterator(interaction.RootFragment);
    next =;
    while ~isempty(next)
        next =;

    More About

    expand all

    Version History

    Introduced in R2024a