matlab.lang.Workspace
Description
A workspace contains variables that you create in
MATLAB® or import into MATLAB from data files or other programs. Use a
matlab.lang.Workspace object to store a copy of the variables in a
workspace. You can pass this object and access it from other workspaces in the same way as any
other variable.
Creation
To create a matlab.lang.Workspace object, use the
matlab.lang.Workspace function (described here) or one of these
functions:
Use
matlab.lang.Workspace.baseWorkspaceto create a workspace object that contains a copy of variables in the base workspace. The base workspace stores variables that you create at the command line. The base workspace includes any variables that scripts create, if you run the script from the command line or from the Editor.Use
matlab.lang.Workspace.currentWorkspaceto create a workspace object that contains a copy of variables in the current workspace. For instance, callmatlab.lang.Workspace.currentWorkspaceinside a function to create a workspace object that contains variables in the function workspace.Use
matlab.lang.Workspace.globalWorkspaceto create a workspace object that contains a copy of global variables.
Syntax
Description
creates a workspace object that contains a copy of variables from the specified
workspace.w = matlab.lang.Workspace(Source=sourceWorkspace)
creates a workspace object that contains a copy of the specified variables from the
specified workspace.w = matlab.lang.Workspace(Source=sourceWorkspace,Variables=varList)
Input Arguments
Output Arguments
Object Functions
matlab.lang.Workspace.baseWorkspace | Store variables from base workspace |
matlab.lang.Workspace.currentWorkspace | Store variables from current workspace |
matlab.lang.Workspace.globalWorkspace | Store variables from global workspace |
variables | Information about workspace variables |
variableNames | Names of variables in workspace |
evaluateAndCapture | Evaluate MATLAB code in specified workspace |
Examples
Version History
Introduced in R2025a