Main Content

Open Models

You can open a blank Simulink® model from the MATLAB® Editor or from the Simulink Editor.

You can open a saved Simulink model, template, or library. You can open the saved file from your file browser, from the MATLAB Editor, from the Simulink Editor, or from the Library Browser in standalone mode.

Tip

If you want to open the model using a file browser and the file browser does not display the model, try changing the file type to All Files.

To open a referenced model from a Model block, double-click the Model block. For more information, see Navigate Model Hierarchy.

Open Simulink

To open Simulink, on the MATLAB Toolstrip, click Simulink.

To open Simulink programmatically, enter this command in the MATLAB Command Window:

simulink

Open Blank Models

When no Simulink models are open, you can open a blank model from the MATLAB Editor:

  1. Open Simulink.

  2. On the Simulink Start Page, in the Simulink menu, click Blank Model.

    Blank Model template icon

When there is already an open Simulink model, you can open a blank model from the Simulink Editor by taking one of these actions:

  • In the Simulink Toolstrip, click New.

  • Select the open model window and press Ctrl+N.

Open Saved Models

Opening a saved model loads the model into memory and displays it in the Simulink Editor.

Note

When MATLAB is not open, you can open a saved model from your operating file system browser.

When MATLAB is open but no Simulink models are open, you can open a saved model by taking one of these actions:

  • In the MATLAB Editor, click Browse for folder . In the file browser that appears, navigate to the folder that contains the model and click Select Folder. Then, in the Current Folder Browser, double-click the model name.

  • Open Simulink. On the Simulink Start Page, in the side bar on the left, select a recent model or project from the list, or click Open.

When there is already an open Simulink model, you can open a saved model from the Simulink Editor:

  1. In the Simulink Toolstrip, on the Simulation tab, click Open.

  2. Click Recent Files to open recent files or Open to search for a model.

When the Simulink Library Browser is open in standalone mode, you can open a saved model from the Library Browser window by clicking Open .

To open a saved model programmatically, in the MATLAB Command Window, enter the name of the model without a file extension, for example, modelName. The model must be in the current folder or on the MATLAB search path.

Load Model Variables and Data from MAT-File

If the data for your model is stored in a MAT-file, to load the data into your MATLAB workspace, first change directory to the file location:

  • In the MATLAB Editor, click Browse for folder .

  • In the file browser that appears, navigate to the folder that contains the MAT-file and click Select Folder.

Then enter this command, where modelName is the name of the MAT-file:

load(modelName);

For more information on how to load variables from a file into the workspace, see load.

Automatically Initialize Variables and Load Data

If you define parameters in your model using variables, you must initialize those variables before the model can run. For example, suppose that you have a model that contains a Gain block. Instead of entering a Gain value, you can specify the variable K as the gain. When you use this approach, you must initialize the variable K before you can run the model.

Also, if your model imports data from the workspace, for example using a From Workspace block, you must load the data into the workspace before you can run the model.

You can use model callbacks to automatically initialize variables and load data. A callback is code that runs at a specified action point, for example after you load or save a model. You can use the callback code to initialize the variables and load the data for your Simulink model at a specified action point. You can specify the action point by choosing the corresponding type of callback.

For example, suppose you have a model that contains:

  • A Gain block with the gain value specified as the variable K.

  • A From Workspace block that is supposed to import data from the file modelData.mat.

If you want K to automatically initialize to a value of 5 and the data from data.mat to automatically load every time your Simulink model finishes loading:

  1. If the Property Inspector is already open and is minimized, restore it by clicking Property Inspector at the right edge of the model window.

    If the Property Inspector is not open, in the Simulink Toolstrip, on the Modeling tab, in the Design section, click Property Inspector.

  2. On the Properties tab, in the Callbacks section, select PostLoadFcn. A PostLoadFcn function is a callback that runs after your model loads.

  3. In the text box, enter this code.

    K=5;
    load(modelData);

    Tip

    Alternatively, you can save the code as a MATLAB script and then enter the name of the script in the text box.

  4. Save the model.

Property Inspector with the PostLoadFcn callback type selected and the commands to initialize K and load model_data in the right pane

Now, every time you load the model, when the model finishes loading, the variable K automatically initializes and data.mat automatically loads.

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

Set Default Template for New Models

You can specify a model template to use as the default template. A new model is created using the default template when you:

  • In the Simulink Toolstrip, click New.

  • Press Ctrl+N.

  • Use the new_system function.

You can create a new template to use as the default template. To create the new template:

  1. Create a model with the configuration settings and blocks you want.

  2. Export the model to a template. See Create Template from Model.

You can set the default template for models and subsystems. To set the default template for models:

  1. Open the Simulink Start Page. In the MATLAB Toolstrip, click Simulink.

  2. On the Start Page, click the title of a template to expand the description.

  3. Click the down arrow next to Create Model and select Set As Default.

    Simulink start page with the Digital Filter template title selected, and the Create Model menu of the template expanded to show the Set as Default option

Default templates have a check mark on the Simulink Start Page.

A model and a subsystem template boxes on the Simulink Start page with check marks above the template titles

When you click the arrow under New in the Simulink Toolstrip, the default templates appear at the top of the list.

The model and subsystem default templates at the top of the options under the New button in the Simulink editor

For models, you can also make the new template the default template programmatically using the Simulink.defaultModelTemplate.

Set Favorite Files

To easily find your favorite models and projects on the Simulink Start Page, add them to the Favorites list on the left tab of the Start Page.

To add a model or project to the Favorites list, in the Recent list, click the star next to the name of your favorite models and projects.

Simulink start page showing a model name in the Recent list, and the cursor hovering to the right of the name over a star symbol with the tooltip text Add to favorites

Clear Recent Files

The Recent list on the Simulink Start Page is a list of the files you most recently opened.

To edit or clear the Recent list, right-click a recent file and click Remove from List or Clear List.

You can also clear the Simulink history programmatically using the Simulink.history.clear function.

Open Model with Different Character Encoding

If you open a MDL file created in a release prior to R2021b in a MATLAB session that uses different encoding, you receive a warning.

For example, suppose you create a MDL file in a MATLAB session configured for Shift_JIS and open it in a session configured for windows-1252. The warning message displays the encoding of the current session and the encoding used to create the model.

Starting in R2021b, MDL files can store characters from any encoding.

To open a MDL file created in a release prior to R2021b in a MATLAB session that uses different encoding, in the environment with the encoding that the MDL file is configured for, resave the file in the R2021b release or later, or resave the MDL file as an SLX file.

See Also

| | |

Related Topics