Main Content

open_system

R2026b

Open model, library, subsystem, or block dialog box

Description

open_system(obj) opens the specified model, library, subsystem, Block Parameters dialog box, or mask dialog box, or runs the specified OpenFcn callback function.

Note

Security Considerations: Before you open the model using open_system, make sure you trust the sender or the author of the model. Models from unknown sources might contain unsafe content. Unknown sources include models you clone from a remote repository, download, or receive as an archive.

Libraries and models, including referenced models, open in a new window. To open a referenced model in the context of a model hierarchy, use the open function with a Simulink.BlockPath object instead.

To take these actions, in the function arguments, specify the corresponding block:

  • Run an OpenFcn callback function.

  • Open a subsystem in a new tab in the same window.

  • Open a mask dialog box.

  • Open a Block Parameters dialog box.

The model or library containing the specified block must be loaded. The function takes the first of these actions that applies:

  1. If the block has an OpenFcn callback function, run the function.

  2. If the block has a mask, open the mask dialog box.

  3. If the block is not a Subsystem block, open the Block Parameters dialog box.

    If the block is a Subsystem block, open the subsystem in a new tab in the same window. Do not open the Block Parameters dialog box.

For example, if a block does not have an OpenFcn callback function, but does have a mask, the mask dialog box opens.

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

  • To look under the mask of a block in a new window or new tab, use Force with Tab or Window.

  • To open the active choice of a Variant Subsystem block in a new tab or a new window, use ActiveChoice with Tab or Window. If one of the arguments is ActiveChoice, then the content inside a masked active choice is opened by passing Force as another argument paired 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 and 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(subsys,"window") opens the specified subsystem in a new Simulink Editor window.

example

open_system(subsys,"tab") opens the subsystem in a new tab in the same Simulink Editor window.

example

open_system(block,"mask") opens the mask dialog box of the specified block.

open_system(block,"force") looks under the mask of a masked block or subsystem. This syntax opens the Block Parameters 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 Inside Mask menu item.

example

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

open_system(block,"parameter") opens the Block Parameters dialog box even if the block has an OpenFcn callback function or a mask.

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

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

example

Examples

collapse all

Suppose you have a model named myModel.

Open the model.

open_system("myModel")

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 model named myModel.

Load the model without opening the model.

open_system("myModel","loadonly")

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. The model contains a subsystem named mySubsystem.

Open the subsystem in a new tab in the same window.

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

Suppose you have a loaded model named myModel that contains a Model block named myRefModelBlock.

Open the referenced model.

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 loaded model named myModel. The model contains a Subsystem block named mySubsystem that contains a Gain block named myBlock. myBlock has no callback functions and no mask.

Open the Block Parameters dialog box of myBlock.

open_system("myModel/mySubsystem/myBlock")

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

Define an OpenFcn callback for the Constant block.

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

Execute the block callback.

open_system("myModel/K")

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

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

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

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

Suppose you have a loaded model that contains 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")

Input Arguments

collapse all

Models, libraries, or subsystems to open, or blocks whose OpenFcn callback function you want to run or whose Block Parameters dialog box you want to open. Specify models and libraries as handles or names. If a model is not on the MATLAB path, specify the file path of the model. On UNIX® systems, the fully model name can start with a tilde (~), which signifies your home directory. Specify subsystems as the handles or paths of the corresponding Subsystem blocks. Specify blocks as handles or block paths.

Format handles as numeric scalars or vectors. Format names and 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.

Example: "myModel"

Example: "myModel/myBlock"

Example: "myModel/mySubsystem"

Example: ["myModel1";"myModel2"]

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

Models or libraries to open., specified as handles or names. If a model is not on the MATLAB path, specify the file path of the model. On UNIX systems, the fully model name can start with a tilde (~), which signifies your home directory.

Format handles as numeric scalars or vectors. Format names and 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.

Example: "myModel"

Example: ["myModel1";"myModel2"]

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

Subsystems to open, specified as the handles or paths of the corresponding Subsystem blocks. Format handles as numeric scalars or vectors. Format names and 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.

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

Subsystems to open, or blocks whose OpenFcn callback function you want to run or whose Block Parameters dialog box you want to open. Specify subsystems as the handles or paths of the corresponding Subsystem blocks. Specify blocks as handles or paths.

Format handles as numeric scalars or vectors. Format names and 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.

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

Variant Subsystem blocks whose active choice you want to open in a new window. Specify the blocks as handles or block paths. Format handles as numeric scalars or numeric arrays Format names and paths as strings, string arrays, character vectors, or cell arrays of character vectors.

For more information on Variant Subsystem block, see Variant Subsystem.

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

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

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