Main Content

new_system

Create Simulink model or library in memory

Description

h = new_system creates a model named untitled (and then untitled1, untitled2, and so on) based on your default model template and returns the new model’s numeric handle. Select your default model template on the Simulink® start page or by using the Simulink.defaultModelTemplate function.

The new_system function does not open the new model. This function creates the model in memory. To save the model, use save_system, or open the model with open_system and then save it using the Simulink Editor.

example

h = new_system(name) creates a model based on your default model template and gives the new model the specified name. This function returns the new model’s numeric handle. Select your default model template on the Simulink start page or by using the Simulink.defaultModelTemplate function.

To avoid shadowing, if name is empty, the new_system function checks loaded models and files on the path and creates a model with the next available name untitled, untitled1, untitled2, and so on.

The new_system function does not open the new model. This function creates the model in memory. To save the model, use save_system, or open the model with open_system and then save it using the Simulink Editor.

h = new_system(name,'FromTemplate',template) creates the model based on the specified template.

example

h = new_system(name,'FromFile',file) creates the model based on the specified model or template.

example

h = new_system(___,'ErrorIfShadowed') creates the model or returns an error if another model, MATLAB® file, or variable with the same name is on the MATLAB path or in the workspace. It uses any of the input arguments in the previous syntaxes.

example

h = new_system(name,'Model') creates an empty model based on the Simulink default model and returns the new model’s numeric handle. The Simulink default model is also known as the root block diagram and has the numeric handle 0. If name is empty, the function creates a model or library named untitled, untitled1, untitled2, and so on.

The new_system function does not open the new model. This function creates the model in memory. To save the model, use save_system, or open the model with open_system and then save it using the Simulink Editor.

example

h = new_system(name,'Model',subsys) creates a model based on the subsystem subsys in a currently loaded model.

example

h = new_system(name,'Subsystem') creates an empty subsystem file that has the specified name.

example

h = new_system(name,'Library') creates an empty library that has the specified name and returns a numeric handle.

example

h = new_system(___,'ErrorIfShadowed') returns an error if another model, MATLAB file, or variable with the same name is on the MATLAB path or in the workspace. This syntax uses any of the input arguments in the previous syntaxes.

example

Examples

collapse all

Create a model in memory named untitled.

h = new_system;

You can use the get_param function to get the name.

get_param(h,'Name')
ans =

    'untitled'

Use the name, the handle, or the get_param function as input to the open_system function.

open_system('untitled')
open_system(h)
open_system(get_param(h,'Name'))

In the Simulink Editor, create the model you want to use as a template. Then, in the Simulation tab, select Save > Template. For this example, name the template mytemplate.

By default, the template is on the MATLAB path, so if you change the template location, add the folder to the MATLAB path.

Create a model named templateModel based on the template mytemplate.

h = new_system('templateModel','FromTemplate','mytemplate');
Invoking template \\myuserdir\Documents\MATLAB\mytemplate.sltx

Create a model named mynewmodel based on an existing model named myoldmodel, which is in the current folder.

h = new_system('mynewmodel','FromFile','myoldmodel.slx');

You can create a new model that contains a subsystem you specify.

Open the example. Then, load the f14 model.

load_system('f14');

Create a new model that contains the Controller subsystem.

new_system('mycontroller','Model','f14/Controller');

Open the new model.

open_system('mycontroller');

Create a library in memory, and then open the library.

new_system('mylib','Library')
open_system('mylib')

Create a subsystem file in memory, and then open the subsystem file.

new_system('mysubsystem','Subsystem')
open_system('mysubsystem')

Create a variable with the name myvar.

myvar = 17;

Try to create a model that uses the same name as the variable. When you use the 'ErrorIfShadowed' option, the new_system function returns an error.

new_system('myvar','Model','ErrorIfShadowed')
The model 'myvar' cannot be created because this name is shadowing another name on the MATLAB
path or in the workspace. Choose another name, or do not use the option 'ErrorIfShadowed'

Input Arguments

collapse all

Name of new model or library, specified as a character vector that:

  • Has 63 or fewer characters

  • Is not a MATLAB keyword

  • Is not 'simulink'

  • Is unique among model names, variables, and MATLAB files on the MATLAB path and in the workspace

Example: 'mymodel', 'mylibrary'

Subsystem to base the new model on, specified as the subsystem block path name in a currently open model.

Example: 'f14/Controller'

Name of the template to base the new model on, specified as a character vector of the name of a template on the MATLAB path. Create a template in the Simulink Editor. In the Simulation tab, select Save > Template.

Example: 'mytemplate', 'mytemplate.sltx'

Path name of the model or template to base the new model on, specified as a character vector. You can use an .mdl, .slx, or ..sltx file. Include the extension and use a full or relative path.

Example: 'Models/mymodel.slx', 'mytemplate.sltx', 'model.mdl'

Version History

Introduced before R2006a