Main Content

commentedBy

Identify objects that implicitly comment out a graphical object

Since R2023a

Description

example

objArray = commentedBy(graphicalObject) returns an array of the explicitly commented objects that cause the graphical object graphicalObject to be commented out. The graphical object is commented out when:

  • The IsExplicitlyCommented property has a value of true. In this case, objArray includes the graphical object.

  • The IsImplicitlyCommented property has a value of true. In this case, objArray includes the explicitly commented states, boxes, or functions that contain the object. Additionally,

    • If graphicalObject is a transition, objArray includes the explicitly commented objects that cause the source or destination to be commented out.

    • If graphicalObject is an entry or exit port, objArray includes the explicitly commented objects that cause the matching entry or exit junction to be commented out.

Examples

collapse all

When you explicitly comment out a state, box, or function, you implicitly comment out all the graphical objects that it contains. For example, when you comment out state A in this chart, you also comment out its substates, A1 and A2.

Stateflow chart with a hierarchy of states. The outer state is called A. It contains two inner states called A1 and A2.

Open the model.

open_system("sfHierarchyAPIExample")

Find the Stateflow.State objects named A, A1, and A2.

sA = find(sfroot,"-isa","Stateflow.State",Name="A");
sA1 = find(sfroot,"-isa","Stateflow.State",Name="A1");
sA2 = find(sfroot,"-isa","Stateflow.State",Name="A2");

Check that state A and its substates are not commented out.

get([sA sA1 sA2], ...
    {"Name","isCommented","isExplicitlyCommented","isImplicitlyCommented"})
ans=3×4 cell array
    {'A' }    {[0]}    {[0]}    {[0]}
    {'A1'}    {[0]}    {[0]}    {[0]}
    {'A2'}    {[0]}    {[0]}    {[0]}

Explicitly comment out states A and A2.

sA.IsExplicitlyCommented = true;
sA2.IsExplicitlyCommented = true;

Verify that state A and its substates are commented out.

get([sA sA1 sA2], ...
    {"Name","isCommented","isExplicitlyCommented","isImplicitlyCommented"})
ans=3×4 cell array
    {'A' }    {[1]}    {[1]}    {[0]}
    {'A1'}    {[1]}    {[0]}    {[1]}
    {'A2'}    {[1]}    {[1]}    {[1]}

Identify the explicitly commented objects that cause each state to be commented out.

get(commentedBy(sA),{"Name"})
ans = 1x1 cell array
    {'A'}

get(commentedBy(sA1),{"Name"})
ans = 1x1 cell array
    {'A'}

get(commentedBy(sA2),{"Name"})
ans = 2x1 cell
    {'A' }
    {'A2'}

Input Arguments

collapse all

Limitations

  • When a graphical object is contained in an atomic subchart or an atomic box, the commentedBy function returns only explicitly commented objects that are also contained in the subchart or box.

Version History

Introduced in R2023a