Main Content

close_system

Close万博1manbetxsystem window or block dialog box

Description

close_systemcloses the current system or subsystem. If the current system is the top-level model and has been modified,close_systemreturns an error.

Use thegcsfunction to determine the current system.

Note

You cannot useclose_systemin a block or menu callback to close the root-level model. Attempting to close the root-level model in a block or menu callback causes an error and discontinues the callback execution.

example

close_system(blockOrSys)closes the specified model or subsystem, or the block dialog box of the specified block. If the model was only loaded, that is, withload_system, this syntax clears the model from memory.

close_system(sys,saveflag)lets you specify whether to save the model with its current name or to close it 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 moreName,Valuepair arguments.

Examples

collapse all

Open the modelvdpand then close it.

vdp close_system

Open the modelvdp.

vdp

In the model, double-click theMublock to open its block dialog box.

Close the block dialog box

close_system('vdp/Mu');

Open a model, modify it, save the model with a new name and close it.

Open the modelvdpand add a block to it.

vdp块= add_block ('vdp/Mu','vdp/Mu','MakeNameUnique','on');

Close the model, saving it with a new name.

close_system('vdp','myvdp');

This command tries to save thevdpsystem to a file with the name'max', but returns an error because'max'is the name of an existing MATLAB®function.

close_system('vdp','max','ErrorIfShadowed',真正的)

Open a model hierarchy, load the referenced model, then close the top model, leaving the referenced model loaded.

Open thesldemo_mdlref_basicmodel and load its referenced model,sldemo_mdlref_counter.

openExample('sldemo_mdlref_basic') load_system('sldemo_mdlref_counter')

Check what models are loaded in memory.

loadedModels = Simulink.allBlockDiagrams('model'); modelNames = get_param(loadedModels,'Name')
modelNames = 2×1 cell array {'sldemo_mdlref_counter'} {'sldemo_mdlref_basic' }

Closesldemo_mdlref_basicwhile keeping the referenced model loaded.

close_system('sldemo_mdlref_basic',0,'closeReferencedModels',false)

Check what models are loaded in memory.

loadedModels = Simulink.allBlockDiagrams('model'); modelNames = get_param(loadedModels,'Name')
modelNames = 'sldemo_mdlref_counter'

Closing the top model clears it from memory. By default, because they share a window, usingclose_systemon the top model would also close the referenced model and clear it from memory. Setting'closeReferencedModels'tofalsekeeps the referenced model,sldemo_mdlref_counter, loaded.

Input Arguments

collapse all

Name of model, subsystem, or the block whose dialog box you want to close, specified as a character vector, cell array of character vectors, string array, handle, or array of handles. Do not use a file extension.

Example:"vdp/Mu"'vdp'

Name of model to close, specified as a character vector, cell array of character vectors, string array, handle, or array of handles. Do not use a file extension.

Option to save model using the current file name, specified as0to close without saving or1to save and then close. Ifsysis an array, you can supply a single character to apply to all of the models in the array. Or you can provide a numeric array with values that correspond with each model in thesysarray.

For information on rules for naming models, seeModel Names.

File to save to, specified as a character vector, cell array of character vectors, or string array. You can specify a model name in the current folder or the full path name, with or without an extension.

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

For information on rules for naming models, seeModel Names.

Name-Value Arguments

Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN, whereNameis the argument name andValueis the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and encloseNamein quotes.

Example:close_system('mymodel','newmodel','closeReferencedModels',false,'ErrorIfShadowed',true,'OverwriteIfChangedOnDisk',true,'SaveModelWorkspace',true)

Option to close all referenced models when you close the window for the top model, specified as the comma-separated pair consisting of'closeReferencedModels'andtrue,false,'on', or'off'. Referenced models that are open in another window are unaffected by this setting. To keep referenced models loaded, set this argument tofalse.

Option to return an error if the new name is already used on the MATLAB path or in the workspace, specified as the comma-separated pair consisting of'ErrorIfShadowed'andtrue,false,'on', or'off'. To receive this error, you must use thenewsysargument to save the model with a new name. To learn about shadowed files, seeShadowed Files.

Option to overwrite the file on disk when you save the model, even if it has been modified since the system was loaded, specified as the comma-separated pair consisting of'OverwriteIfChangedOnDisk'andtrue,false,'on', or'off'. By default, if the file changed on disk since the model was loaded,close_systemdisplays an error to prevent the changes on disk from being overwritten.

You can control whether saving the model displays an error if the file has changed on disk by using a Simulink preference. In theModel Filepane of the Simulink Preferences dialog box, underChange Notification, selectSaving the model. This preference is on by default.

Option to save the model workspace when you save the model, specified as the comma-separated pair consisting of'SaveModelWorkspace'andtrue,false,'on', or'off'. The model workspaceDataSourcemust be a MAT-file. If the data source is not a MAT-file, saving the model does not save the workspace. SeeSpecify Source for Data in Model Workspace.

Version History

Introduced before R2006a

expand all

Behavior changed in R2019b