Main Content

new_system

R2026b

Create Simulink model or library in memory

Description

handle = new_system creates a model named untitled (and then untitled1, untitled2, and so on) based on your default model template and returns the numeric handle of the new model.

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.

example

handle = new_system(name) creates the model with the specified name.

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.

example

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

example

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

example

handle = new_system(name,"Model") creates an empty model based on the Simulink default model and returns the numeric handle of the new model. 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.

example

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

example

handle = new_system(name,"Subsystem") creates an empty subsystem file with the specified name.

example

handle = new_system(name,"Library") creates an empty library with the specified name.

example

handle = new_system(___"ErrorIfShadowed") can be used with any of the inputs from the previous syntaxes and takes the same action, but returns an error when the action creates something with the same names as another model, MATLAB® file, or variable on the MATLAB path or in the workspace.

example

Examples

collapse all

Create two models in memory based on the default template. Create the first model with the default name, and the second model with the name myModel.

Create the model with the default name.

h1 = new_system;

Use the get_param function to get the name of the new model.

get_param(h1,"Name")
ans =

    'untitled'

Create the model named myModel.

h2 = new_system("myModel");

Suppose you have a custom template named myTemplate on the MATLAB path.

Create a model named myModel based on the template.

h = new_system("myModel",FromTemplate="myTemplate");

Suppose you have a model named myModel1 on the MATLAB path.

Create a model named myModel2 based on myModel1.

h = new_system("myModel2",FromFile="myModel1");

Create an empty model named myModel based on the Simulink default model (root block diagram).

h = new_system("myModel","Model");

Suppose you have a loaded model named myModel1 that contains a subsystem named mySubsystem. Create a new model named myModel2 based on the subsystem.

h = new_system("myModel2",Model="myModel1/mySubsystem");

Create an empty subsystem file with the name mySubsystem.

h = new_system("mySubsystem","Subsystem");

Create a library named myLibrary.

h = new_system("myLibrary","Library");

Create a variable with the name cycle.

cycle = 3;

Try to create a model that uses the same name as the variable using the ErrorIfShadowed option.

new_system("cycle","ErrorIfShadowed")
The model 'cycle' 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 string or character vector that:

  • Has 150 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"

Subsystem to base the new model on, specified as the Subsystem block path in a currently open model. Format the path as a string or character vector.

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

Example: "myModel/mySubsystem"

Data Types: string | character vector

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

Example: "mytemplate", "mytemplate.sltx"

Data Types: string | character vector

Path name of the model or template to base the new model on, specified as a string or 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"

Data Types: string | character vector

Output Arguments

collapse all

Numeric handle of new model or library, returned as a double.

Data Types: double

Version History

Introduced before R2006a