Each model is provided with its own workspace for storing variable values.
The model workspace is similar to the base MATLAB® workspace except that:
Variables in a model workspace are visible only in the scope of the model.
If both the MATLAB workspace and a model workspace define a variable of the same name, and the variable does not appear in any intervening masked subsystem or model workspaces, the Simulink® software uses the value of the variable in the model workspace. A model's workspace effectively provides it with its own name space, allowing you to create variables for the model without risk of conflict with other models.
When the model is loaded, the workspace is initialized from a data source.
The data source can be a Model file, a MAT-file, a MATLAB file, or MATLAB code stored in the model file. For more information, see Data source.
You can interactively reload and save MAT-file, MATLAB file, and MATLAB code data sources.
To store a data object in a model workspace, set the
storage class of the object to
Auto. Data objects
are objects of these classes:
If you specify a storage class other than
you must store data objects in the base workspace or a data dictionary
to ensure the objects are unique within the global Simulink context
and accessible to all models.
In general, parameter variables in a model workspace are not tunable in the code generated from a model.
However, you can tune model workspace variables declared as model arguments for referenced models. For more information, see Model Arguments.
Note: When resolving references to variables used in a referenced model, the variables of the referenced model are resolved as if the parent model did not exist. For example, suppose a referenced model references a variable that is defined in both the parent model's workspace and in the MATLAB workspace but not in the referenced model's workspace. In this case, the MATLAB workspace is used.
When you use a workspace variable as a block parameter, Simulink creates a copy of the variable during the compilation phase of the simulation and stores the variable in memory. This can cause your system to run out of memory during simulation, or in the process of generating code. Your system might run out of memory if you have:
Large models with many parameters
Models with parameters that have a large number of elements
This issue does not affect the amount of memory that is used to represent parameters in generated code.
An object of the
describes a model workspace. Simulink creates an instance of
this class for each model that you open during a Simulink session.
The methods associated with this class can be used to accomplish a
variety of tasks related to the model workspace, including:
Listing the variables in the model workspace
Assigning values to variables
Clearing the model workspace
Reloading the model workspace from the data source
Saving the model workspace to a specified MAT-file or MATLAB file
Saving the workspace to the MAT-file or MATLAB file that the workspace designates as its data source