Main Content

bdroot

R2026b

Top-level model of current system

Description

model = bdroot returns the top-level model of the current system.

The current system is one of these:

  • During editing, the most recently clicked subsystem or the subsystem that contains the most recently clicked block; if the most recent click is in the top level of the model hierarchy, the current system is the model.

  • During simulation of a model that contains an S-Function block, the subsystem containing the S-Function block currently being evaluated; if the S-Function being evaluated is in the top level of the model hierarchy, the current system is the model.

  • When a callback is invoked, the model, subsystem, or block invoking the callback; the current system can change during the execution of the callback, for example if you set breakpoints or interact with an editor.

  • During evaluation of the MaskInitialization function, the subsystem containing the block whose mask is being evaluated; if the mask is in the top level of the model hierarchy, the current system is the model.

  • The model most recently loaded into memory with the load_system function.

    If you load a model using the load_system function and then change the current system, loading the model a second time using the load_system function does not make the model the current system. To make the model the current system, close the model and then reload the model using the load_system function.

example

model = bdroot(elements) returns the top-level model of the specified model elements. To use the bdroot function, each element in elements must be loaded.

example

Examples

collapse all

Suppose you have a model named myModel1 that is open in Simulink®. The model contains a Subsystem block and a Model block. The Model block references a model named myModel2.

Navigate into the subsystem.

Get the top-level model of the current model.

bdroot
'myModel1'

Navigate into the model reference.

Get the top-level model of the current model.

bdroot
'myModel2'

Suppose you have a loaded model that contains a Subsystem block. The subsystem contains a Gain block with the handle hBlock.

Get the handle of the top-level model containing the Gain block.

hTopLevel = bdroot(hBlock);

Input Arguments

collapse all

Models or model elements whose top-level model you want to get, specified as one or more handles, model names, file paths or block paths. Format handles as numeric scalars or numeric arrays. Format model names, model paths, and block paths as strings, string arrays, character vectors, or cell arrays of character vectors.

For information about getting handles and paths, see Get Handles and Paths.

Tip

Use bdroot with gcs, gcb, and gcbh to get the top-level model of the current system or block.

Example: "myModel/mySubsystem"

Data Types: double | array of doubles | string | string array | character vector | cell array of character vectors

Output Arguments

collapse all

Top-level model, returned as a handle or a model name of the same data type as the elements arguments. If you specify more than one element argument, the function returns an array.

Data Types: double | array of doubles | string | string array | character vector | cell array of character vectors

Version History

Introduced before R2006a