Model Workspaces - MATLAB & Simulink (original) (raw)

Main Content

Model Workspace Differences from MATLAB Workspace

Each model is provided with its own workspace for storing variable values.

The model workspace is similar to the base MATLABĀ® workspace except that:

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.

Troubleshooting Memory Issues

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:

This issue does not affect the amount of memory that is used to represent parameters in generated code.

Manipulate Model Workspace Programmatically

For most common data management tasks, regardless of data source, you can use theSimulink.data.connect function to create a connection to your data source, then use the common set of functions provided by the Simulink.data.DataConnection object. For more information, see Manage Design Data for Simulink Models Programmatically.

For tasks specific to a model workspace, use a Simulink.ModelWorkspace object. An object of the Simulink.ModelWorkspace class 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:

See Also

Simulink.ModelWorkspace | Simulink.data.DataConnection | Simulink.data.connect

Topics