new_system

Create Simulink model or library in memory

Description

example

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.

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.

If name is empty, the function creates a model 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,'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.

Examples

collapse all

Create a model in memory called untitled.

h = new_system;

You can use get_param to get the name.

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

untitled

Use the name, the handle, or get_param command as input to open_system. You can use any of these commands:

Before you use this syntax, create a template. In the Simulink Editor, create the model you want to use as the 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 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 myoldmodel, which is in the current folder.

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

Load the model f14. Create a model based on the Controller subsystem.

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

Create a library in memory and then open it.

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

Create a subsystem file in memory and then open it.

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('myvar2','Model','ErrorIfShadowed')
The model 'myvar2' 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'

Introduced before R2006a