Create Models and Open Existing Models

Create a Model

  1. On the MATLAB® Home tab, click Simulink.

  2. In the Simulink® start page, choose a template or search the templates.

    Model templates are starting points to apply common modeling approaches. They help you reuse settings and block configurations and share knowledge. Use model and project templates to apply best practices and take advantage of previous modeling solutions.

    Click the title of a template to read the description.

    To locate templates that are not on the MATLAB search path, click Open. Model templates have the extension .sltx.

  3. After selecting the template you want, click Create Model.

    To use a template without reading the description, click the template image. Alternatively, press Ctrl+N to use your default template. To set a default template, see Use Customized Settings When Creating New Models.

    A new model using the template settings and contents opens in the Simulink Editor. For next steps, see Build and Edit a Model in the Simulink Editor.

If the built-in templates do not meet your needs, try the Examples tab, or you can create your own templates. See Create a Template from a Model.

Use Customized Settings When Creating New Models

You can specify a model template to use for all new models.

  1. Create a model with the configuration settings and blocks you want, then export the model to a template. See Create a Template from a Model.

  2. To reuse these settings in every new model, make the new template your default model template using the Simulink start page or the Simulink.defaultModelTemplate function.

    In the start page, click the title of a template to expand the description, then click the down arrow next to Create Model and select Set As Default.

After you set a default model template, every new model uses that template, for example, when you press Ctrl+N, when you use new model buttons, or when you use new_system. In the Simulink Editor, your default template name is at the top of the list when you select File > New > MyDefaultTemplateName.

The default template shows a tick mark in the start page.

Open a Model

Opening a model loads the model into memory and displays it in the Simulink Editor. Use any of these techniques:

  • On the MATLAB Home tab, click Simulink. In the Simulink Start Page, select a recent model or project from the list, or click Open.

  • In the Simulink Editor, select File > Open Recent and choose a recent model.

  • At the MATLAB command prompt, enter the name of the model without a file extension, for example, vdp. The model must be in the current folder or on the MATLAB search path.

  • In the Simulink Library Browser, click the Open model or library button .

  • Open the model using the Current Folder browser or your operating system file browser.

To clear the list of recent files in the start page, in MATLAB, enter:


Load Variables When Opening a Model

As you build models, you sometimes define variables for a model. For example, suppose that you have a model that contains a Gain block. You can specify the variable K as the gain rather than setting the value on the block. When you use this approach, you must define the variable K for the model to simulate.

You can use a model callback to load variables when you open a model.

  1. In a model that uses the Gain block, set the block Gain value to K.

  2. Define the variable in a MATLAB script. In MATLAB, select New > Script. In the script, enter your variable definitions:


  3. Save the script as loadvar.m.

  4. In the model, open the Property Inspector. Select View > Property Inspector. With no selection at the top level of a model, you can use the Property Inspector to set model properties. Otherwise, use File > Model Properties.

  5. In the Callbacks section of the model properties, select PreLoadFcn as the callback that you want to define. In the pane, enter loadvar.

  6. Save the model.

The next time that you open the model, the PreloadFcn callback loads the variables into the MATLAB workspace.

To learn about callbacks, see Callbacks for Customized Model Behavior. To define a callback for loading variables programmatically, see Programmatically Load Variables When Opening a Model.

Open a Model with Different Character Encoding

If you open an MDL file that uses a particular character set encoding in a MATLAB session that uses a different encoding, a warning appears. For example, suppose that you create an MDL file in a MATLAB session configured for Shift_JIS and open it in a session configured for US_ASCII. The warning message shows the encoding of the current session and the encoding used to create the model.

SLX files do not warn because they can store characters from any encoding.

If you encounter any problems with corrupted characters, for example when using MATLAB files associated with the model, then try using the slCharacterEncoding function to change the character encoding of the current MATLAB session to match the model character encoding.

Simulink can check if models contain characters unsupported in the current locale. For more details, see Check model for foreign characters and Save Models with Different Character Encodings.

Simulink Model File Types

New models that you create have the .slx extension by default. Models created before R2012b have the extension .mdl. Models you can edit can have the .slx or .mdl extension, depending on when they were created or whether you converted them. See Save Models in the SLX File Format.

.slxp and .mdlp extensions denote protected models that you cannot open and edit. See Protected Model. Model templates have the extension .sltx.

Simulink libraries also use the .slx extension, but you cannot simulate them. To learn more, see Create a Custom Library.

See Also

| | | |

Related Examples

More About

Was this topic helpful?