Main Content

matlab.lang.Workspace.currentWorkspace

Store variables from current workspace

Since R2025a

    Description

    w = matlab.lang.Workspace.currentWorkspace creates a workspace object that contains a copy of variables in the current workspace.

    example

    Examples

    collapse all

    Create a function that uses matlab.lang.Workspace.currentWorkspace to create a workspace object that stores the variables in the current function workspace.

    function wCurrent = exampleFunction(input)
    localVar = input + 5;
    wCurrent = matlab.lang.Workspace.currentWorkspace;
    end

    Run exampleFunction.

    wCurrent = exampleFunction(5)
    wCurrent = 
    Workspace with variables:
    
          Name      Size    Class 
        ________    ____    ______
    
        input       1x1     double
        localVar    1x1     double
    
    

    Version History

    Introduced in R2025a