Main Content

gcs

R2026b

Get path of current system

Syntax

Description

sys = gcs returns the path 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.

If you close the model that contains the current system, another open or loaded model becomes the current system. Use gcs to find out the new current system.

To explicitly set the current system, take one of these actions:

  • Use set_param with the CurrentSystem parameter on the root Simulink® model, for example:

    set_param(0,CurrentSystem="myModel")

  • Open the model by using open_system or the model name at the MATLAB® command prompt.

To get the current model, use the bdroot function.

example

Examples

collapse all

Suppose you have two models on the MATLAB path named myModel1 and myModel2.

Load myModel1.

load_system("myModel1");

Load myModel2.

load_system("myModel2");

Get the current system.

gcs
ans = 
'myModel2'

The current system is myModel2 because it is the most recently loaded model.

Clear myModel2 from memory.

close_system("myModel2")

Get the current system.

gcs
ans = 
'myModel1'

The current system is myModel1 because it was the current system before myModel2.

Output Arguments

collapse all

Current system, returned as a model name or Subsystem block path. The name or path is formatted as a character vector.

Data Types: character vector

Version History

Introduced before R2006a

See Also

| |