Contenido principal

close_system

R2026b

Close Simulink model window or Block Parameters dialog box

Description

close_system closes the current system, subsystem, or Block Parameters dialog box. Use the gcs function to determine the current system. If the current system is the top-level model and has been modified, the function returns an error.

Note

Using the close_system function in a block or menu callback to close the root-level model is not supported. Attempting to close the root-level model in a block or menu callback causes an error and discontinues the callback execution.

Tip

When you close a model with the close_system function, the model is no longer loaded. To close a model but keep the model loaded, use this command instead, where mdl is the handle or name of the model.

set_param(mdl,Open="off")
To unload the model after running this command, you can use the close_system or bdclose function.

example

close_system(blockOrSys) closes the specified model or subsystem, or the Block Parameters dialog box of the specified block. If the block has a mask, this syntax closes the mask dialog box. If the model was only loaded, this syntax clears the model from memory.

example

close_system(sys,saveflag) either saves the model with its current name or closes the model without saving.

example

close_system(sys,newSys) saves the model to a file with the specified name before closing.

example

close_system(sys,___,Name=Value) specifies additional options using one or more Name=Value pair arguments.

Examples

collapse all

Suppose you open two models sequentially. First, you open a model named myModel1, and then a model named myModel2.

Close the current system.

close_system

The second model you open is the current system, so the command closes myModel2. Once myModel2 closes, myModel1 becomes the current system.

Run the command again.

close_system

The command closes myModel1.

Suppose you have two open models, named myModel1 and myModel2. The model named myModel1 is the current system.

Close the model named myModel2.

close_system("myModel2")

Suppose you have an open model named myModel containing a block named myBlock. The Block Parameters dialog box of myBlock is open.

Close the dialog box.

close_system("myModel/myBlock")

Suppose you have an open model named myModel.

Close and save the model.

close_system("myModel",1)

Suppose you have an open model named myModel1.

Save the model with the new name myModel2, and then close the model. Return an error if the new name is shadowed — when the name is already used on the MATLAB® path or in the workspace.

close_system("myModel1","myModel2",ErrorIfShadowed=true)

Input Arguments

collapse all

Model, subsystem, or Block Parameters dialog box to close. Specify models using handles or names. Specify subsystems using handles or paths of the corresponding Subsystem blocks. Specify Block Parameter dialog boxes using the handles or paths of the corresponding blocks.

Format the handles as numeric scalars or numeric arrays. Format the names and paths as strings, string arrays, character vectors, or cell arrays of character vectors. Do not specify file extensions in the names or paths.

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

Example: "myModel" "myModel/mySubsystem""myModel/myBlock"["myModel1";"myModel2"]

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

Model or subsystem to close. Specify models using handles or names. Specify subsystems using handles or paths of the corresponding Subsystem blocks.

Format the handles as numeric scalars or numeric arrays. Format the names and paths as strings, string arrays, character vectors, or cell arrays of character vectors. Do not specify file extensions in the names or paths.

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

Example: "myModel" "myModel/mySubsystem"["myModel1";"myModel2"]

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

Option to save model using the current file name, specified as 0 to close without saving or 1 to save and then close. If sys is an array, specifying 0 or 1 applies the value to all models in the array. To assign different saveflag values to different models in the array, specify an array of saveflag values instead, where each element in the array has a value of 0 or 1.

Data Types: logical | array of logicals

Name with which the file is saved before closing, specified as a string, string array, character vector, or cell array of character vectors. You can specify a model name in the current folder or the file path, with or without an extension.

When you specify a name without an extension, the model saves in the file format specified in your Simulink® preferences. Possible model extensions are .slx and .mdl.

For information on rules for naming models, see Choose Valid Model File Names.

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: close_system("myModel",ErrorIfShadowed=true,SaveModelWorkspace=true)

Option to close all referenced models when you close the window for the top model. Referenced models that are open in another window are not affected. To turn the option on, specify the value as true or "on". To turn the option off, specify the value as false or "off".

Data Types: string | character vector | logical

Option to return an error if the new name is already used on the MATLAB path or in the workspace. To turn the option on, specify true or "on". To turn the option off, specify the value as false or "off".

To receive this error, you must use the newsys argument to save the model with a new name. To learn about shadowed files, see Shadowed Files.

Data Types: string | character vector | logical

Option to overwrite the file on disk when you save the model, even if it has been modified since the model was loaded. To turn the option on, specify true or "on". To turn the option off, specify the value as false or "off".

By default, if the file changed on disk since the model was loaded, the function displays an error to prevent the changes on disk from being overwritten. You can control whether the function displays an error if the file has changed on disk using a Simulink preference. In the Model File pane of the Simulink Preferences dialog box, under Change Notification, select Saving the model. This preference is on by default.

Data Types: string | character vector | logical

Option to save the model workspace when you save the model. To turn the option on, specify true or "on". To turn the option off, specify the value as false or "off".

The model workspace DataSource must be a MAT file. If the data source is not a MAT file, saving the model does not save the workspace. See Specify Source for Data in Model Workspace.

Data Types: string | character vector | logical

Version History

Introduced before R2006a

expand all