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
.
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:
Open Simulink.
On the Simulink Start Page, in the Simulink menu, click Blank Model.
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
To open a model created in a later version of Simulink in a previous version, first export the model to the previous version. See Export Model to Previous Version of Simulink.
.slxp
and.mdlp
extensions denote protected models that you cannot open or edit. See Reference Protected Models from Third Parties.
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:
In the Simulink Toolstrip, on the Simulation tab, click Open.
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. You can specify the variable K
as the gain
rather than setting the value on the block. 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:
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.
On the Properties tab, in the Callbacks section, select
PostLoadFcn
. APostLoadFcn
function is a callback that runs after your model loads.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.
Save the model.
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:
Create a model with the configuration settings and blocks you want.
Export the model to a template. See Create Template from Model.
To set the default template:
To open the Simulink Start Page, in the MATLAB Toolstrip, click Simulink.
On the Start Page, click the title of a template to expand the description.
Click the down arrow next to Create Model and select Set As Default.
The default template has a check mark on the Simulink Start Page.
When you click the arrow under New in the Simulink Toolstrip, the default template appears at the top of the list.
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.
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
simulink
| open_system
| Simulink.defaultModelTemplate
| Simulink.history.clear