Main Content

getChildren

标识对象的子级

说明

示例

objArray = getChildren(parent) 返回一个具有指定父级的对象数组。

示例

全部折叠

此图有两个子级,即状态 A 和默认转移。状态 A 有四个子级,即状态 A1、状态 A2 和两个转移。

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

打开模型并访问图的 Stateflow.Chart 对象。

open_system("sfHierarchyAPIExample")
ch = find(sfroot,"-isa","Stateflow.Chart");

标识图的子级。显示子级的对象类型。

children = getChildren(ch);
classes = arrayfun(@class,children,UniformOutput=false)
classes = 2x1 cell
    {'Stateflow.State'     }
    {'Stateflow.Transition'}

children 中的一个元素是状态。显示该状态的名称。

idx = (classes=="Stateflow.State");
state = children(idx);
state.Name
ans = 
'A'

标识状态 A 的子级。显示子级的对象类型。

grandchildren = getChildren(state);
classes = arrayfun(@class,grandchildren,UniformOutput=false)
classes = 4x1 cell
    {'Stateflow.State'     }
    {'Stateflow.State'     }
    {'Stateflow.Transition'}
    {'Stateflow.Transition'}

grandchildren 中的两个元素是状态。显示状态的名称。

idx = (classes=="Stateflow.State");
grandchildren(idx).Name
ans = 
'A1'
ans = 
'A2'

输入参数

全部折叠

版本历史记录

在 R2006a 之前推出