Main Content

Simulink.sdi.setLegendPosition

Set legend position in Simulation Data Inspector

Since R2023b

    Description

    Simulink.sdi.setLegendPosition(pos) sets the position of the legend in the Simulation Data Inspector using the position pos.

    example

    Examples

    collapse all

    Simulate the model vdp.

    mdl = "vdp";
    sim(mdl);

    Open the Simulation Data Inspector.

    Simulink.sdi.view

    Select signals from the table on the left to view them in the Simulation Data Inspector. By default, the legend is located outside of the subplot at the top-left.

    The legend is located outside the plot area at the top-left. The signals in the legend are aligned horizontally.

    Use the Simulink.sdi.setLegendPosition function to move the legend inside the subplot and to the right.

    Simulink.sdi.setLegendPosition("InsideRight")

    The legend is located inside the subplot in the upper right corner. The signals in the legend are aligned vertically.

    You can confirm the location of the legend programmatically using the Simulink.sdi.getLegendPosition function.

    Simulink.sdi.getLegendPosition
    ans = 
    'InsideRight'
    

    You can also use the Simulink.sdi.setLegendPosition function to remove the legend.

    Simulink.sdi.setLegendPosition("None")

    The legend is no longer visible.

    Input Arguments

    collapse all

    Legend position in the Simulation Data Inspector, specified as one of these values:

    • "OutsideTop" — Outside the subplot area on the top-left

    • "OutsideRight" — Outside the subplot area on the top-right

    • "InsideTop" — Inside the subplot area on the top-left

    • "InsideRight" — Inside the subplot area on the top-right

    • "None" — No legend

    When the legend position is "OutsideTop" or "InsideTop", the software lists legend entries horizontally. When the legend position is "OutsideRight" or "InsideRight", the software lists legend entries vertically.

    Version History

    Introduced in R2023b