Main Content

open_system

Open model, library, subsystem, or block dialog box

Description

open_system(obj) opens the specified model, library, subsystem, or block.

A model or library opens in a new window. For a subsystem or block within a model, the behavior depends on the type of block and its properties.

  • Any OpenFcn callback for the block or model is evaluated.

  • If block or model has no OpenFcn callback, and a mask is defined, the mask parameter dialog box opens.

  • Without an OpenFcn callback or a mask parameter, the software opens the object.

    • A referenced model opens in a new window.

      Tip

      To open the referenced model in the context of a model hierarchy, use the open function with a Simulink.BlockPath object.

    • A subsystem opens in a new tab in the same window.

    • For blocks, the Block Parameters dialog box for the block opens.

To open a specific subsystem or block, you must load the model or library that contains the block. Otherwise the software issues an error.

You can override the default behavior by specifying more than one input argument. The following are valid combination of arguments:

  • Using Force with Tab or Window allows you to look under the mask of a block in a new window or a new tab.

  • Using ActiveChoice with Tab or Window opens the active choice of a Variant Subsystem block in a new tab or a new window. If one of the arguments is ActiveChoice, then the content inside a masked active choice is opened by passing Force as another argument along with Tab or Window.

The following combinations of input arguments will error out.

  • If you specify arguments parameter, mask, and OpenFcn with any other argument except ActiveChoice.

  • If you specify ActiveChoice on any other block other than a Variant Subsystem block.

  • If you specify force with any other argument other than ActiveChoice, window, or tab.

  • If you specify both window or tab as arguments.

  • If you specify loadonly with any other argument.

example

open_system(sys,"loadonly") loads the specified model or library without opening the Simulink® Editor. Using this syntax is equivalent to calling the load_system function.

example

open_system(sbsys,"window") opens the subsystem sbsys in a new Simulink Editor window. Before opening a specific subsystem or block, load the model or library that contains the subsystem or block. Otherwise the software issues an error.

example

open_system(sbsys,"tab") opens the subsystem in a new tab in the same Simulink Editor window. Before opening a specific subsystem or block, load the model or library that contains the subsystem or block. Otherwise the software issues an error.

open_system(blk,"mask") opens the mask dialog box of the block or subsystem specified by blk. Load the model or library that contains blk before opening it.

example

open_system(blk,"force") looks under the mask of a masked block or subsystem. This syntax opens the dialog box of the block under the mask or opens a masked subsystem in a new tab in the Simulink Editor. Using this syntax is equivalent to the Look Under Mask menu item. Before opening a specific subsystem or block, load the model or library that contains the subsystem or block. Otherwise, the software issues an error.

open_system(blk,"parameter") opens the Block Parameters dialog box.

open_system(blk,"OpenFcn") runs the OpenFcn callback for the block blk.

open_system(vssblk,"ActiveChoice","window") opens the active choice of the Variant Subsystem in a new window.

example

open_system(blk,"force","window") opens the content in a masked subsystem in a new window.

example

Examples

collapse all

Suppose you have a model named myModel.

Open the model.

open_system("myModel")

Suppose you have a model named myModel.

Load the model without opening it.

load_system("myModel")

Suppose you have a model named myModel. The model contains a subsystem named mySubsystem.

Open the subsystem.

load_system("myModel")
open_system("myModel/mySubsystem")

Suppose you have a model named myModel. The model contains a subsystem named mySubsystem.

Open the subsystem in a new tab.

load_system("myModel")
open_system("myModel/mySubsystem","tab")

Suppose you have a model named myModel. The model contains a subsystem named mySubsystem.

Open the subsystem in its own Simulink Editor window.

load_system("myModel")
open_system("myModel/mySubsystem","window")

Suppose you have a model named myModel that uses a Model block named myRefModelBlock to reference another model.

Open the referenced model.

load_system("myModel")
open_system("myModel/myRefModelBlock")

The referenced model opens in its own Simulink Editor window as a top model.

Tip

To open the referenced model in the context of a model hierarchy, use the open function with a Simulink.BlockPath object.

Suppose you have a model named myModel. The model contains a subsystem named mySubsystem that contains multiple Gain blocks.

Open the Block Parameters dialog box for the first Gain block in the subsystem.

load_system("myModel")
open_system("myModel/mySubsystem/Gain")

Suppose you have a model named myModel that contains a Constant block named K.

Define an OpenFcn callback for the Constant block.

load_system("myModel")
set_param("myModel/K",OpenFcn="disp('Hello World!')")

Execute the block callback.

open_system("myModel/K","OpenFcn")

The words Hello World appear in the MATLAB® Command Window.

Suppose you have a model named myModel. The model contains a masked subsystem named myMaskedSubsystem.

Open the contents of the masked subsystem.

load_system("myModel")
open_system("myModel/myMaskedSubsystem","force")

Suppose you have two models, myModel1 and myModel2. You can open both models with a single command.

Create a string array of the model names.

models = ["myModel1","myModel2"]

Open the models.

open_system(models)

Suppose you have a Variant Subsystem block named vssBlock. The Variant Subsystem contains two variant choices.

Open the active choice of the Variant Subsystem in a new window

open_system("vssBlock","ActiveChoice","window")

Suppose you have a model named myModel. The model contains a masked subsystem named myMaskedSubsystem.

Open the contents of the masked subsystem in a new tab.

load_system("myModel")
open_system("myModel/myMaskedSubsystem","force","tab")

Input Arguments

collapse all

Model, referenced model, library, subsystem, or block path, specified as a string or a character vector. To open multiple of these, specify the paths as a string array or cell array of character vectors. If the model you want to open is not on the MATLAB path, specify the full path to the model file. Specify the block or subsystem using its full name (for example f14/Controller/Gain) on an opened or loaded model. On UNIX® systems, the fully qualified path name of a model can start with a tilde (~), which signifies your home directory.

Data Types: string | char

Full name or path of model or library, specified as a string or a character vector. To open multiple of these, specify the names or paths as a string array or cell array of character vectors.

Data Types: string | char

Full name or path of subsystem in an open or loaded model, specified as a string or a character vector. To open multiple of these, specify the names or paths as a string array or cell array of character vectors.

Data Types: string | char

Full name or path of block or subsystem in open or loaded model, specified as a string or a character vector. To open multiple of these, specify the names or paths as a string array or cell array of character vectors.

Data Types: string | char

Full name or path of Variant Subsystem block in open or loaded model, specified as a string or a character vector. To open multiple of these, specify the names or paths as a string array or cell array of character vectors. For more information on Variant Subsystem block, see Variant Subsystem.

Data Types: string | char

Tips

To open a referenced model in the context of a model hierarchy, use the open function with a Simulink.BlockPath object.

Version History

Introduced before R2006a