Documentation

new_system

Create Simulink model or library in memory

Syntax

  • h = new_system(name)
  • h = new_system(name,'FromTemplate',template)
    example
  • h = new_system(___,'ErrorIfShadowed')
    example
  • h = new_system(name,'Model')
  • h = new_system(name,'Model',subsys)
    example
  • h = new_system(name,'Library')
    example
  • h = new_system(___,'ErrorIfShadowed')
    example

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.

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(___,'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.

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.

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,'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')
ans =

untitled

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

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

Before you use this syntax, create a template. In the Simulink Editor, create the model you want to use as the template. Then select File > Export Model to > 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

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 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 using File > Export Model to > Template.

Example: 'mytemplate', 'mytemplate.sltx'

Introduced before R2006a

Was this topic helpful?