Reputation: 603
In Matlab/Simulink, is there a convenient way to determine the depth of the current system, i.e. the numbers of system block borders one has to cross to reach the root level from there? I suppose you can get the pathname of the current system by gcb
and count the number of slashes, but that doesn't seem to be a very natural way to do it.
Upvotes: 2
Views: 744
Reputation: 1644
You can ask for the parent in a loop, until the system doesn't have a parent,
depth = 1;
parent = get_param(system, 'Parent');
while ~isempty(parent)
depth = depth + 1;
parent = get_param(parent, 'Parent');
end
I didn't try this, but I think it should work.
Upvotes: 1